Hi Mike,
When you're running SETX you're entering your specific user information as well as server and port info, right? Sorry if that's a silly question, but just wanted to make sure. In lieux of using SETX in the command line to reset the environment variables, you could also include urllib2 proxy handlers directly in the get_response def as shown below -- this is probably a more elegant solution:
def get_response(url, query='', get_json=True):
opener = urllib2.build_opener(
urllib2.HTTPHandler(),
urllib2.HTTPSHandler(),
urllib2.ProxyHandler(
{'https': 'http://yourUserName:yourPassword@YourProxyIP:ProxyPort',
'http': 'http://yourUserName:yourPassword@YourProxyIP:ProxyPort',
))
urllib2.install_opener(opener)
encoded = urllib.urlencode(query)
request = urllib2.Request(url, encoded)
if get_json:
return json.loads(urllib2.urlopen(request).read())
return urllib2.urlopen(request).read()
If you don't want to hardcode your info into the proxy handler, you could use this instead, which would allow you to enter your credentials via the command line:
{'https': 'http://' + sys.argv[1] + ':' + sys.argv[2] + '@YourProxyIP:ProxyPort',
'http': 'http://' + sys.argv[1] + ':' + sys.argv[2] + '@YourProxyIP:ProxyPort'}
If you do it this way, don't forget to import the sys module at the top of your script: import sys
You'd then enter the name of the script and your credentials in the python prompt like this:
>>> nameOfScript yourUserName yourPassword
Keep in mind that if you have special characters in your credentials (@, &, etc.) yourUserName and yourPassword need to be surrounded by double quotes.
Hope this works for you, please let me know if you need any more pointers.
- Trill