Python urllib requesting multiple times -


i've written following python code connects url data using json. however, when server logs these requests, being made twice each time.

i assuming has fact it's first using try , re-requesting url if try method met. suggestions on how can make it's sending request server once? thanks

            import json             import urllib.request, urllib.error, urllib.parse              remoteurl = "http://192.168.0.29/" + "?id=" + id             json_obj = urllib.request.urlopen(remoteurl)               try:                 urllib.request.urlopen(remoteurl) response:                     if response.read(1):                         string = json_obj.read().decode('utf-8')                         json_obj = json.loads(string)                         responsename = json_obj['name']                         print(responsename)                     else:                         print("error")             except:                 print("url failed") 

first request:

json_obj = urllib.request.urlopen(remoteurl) 

second request:

with urllib.request.urlopen(remoteurl) response: 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -