4

I am trying to use Spyder for Python/Tensorflow within a company's network. Unfortunately I cannot disable the Firewall, which brings some Proxy problems with it.

Using this very basic code

import tensorflow as tf
learn = tf.contrib.learn
tf.logging.set_verbosity(tf.logging.ERROR)
mnist = learn.datasets.load_dataset('mnist')

throws following error

File "C:\Users\xxx\AppData\Local\Continuum\Anaconda3\lib\urllib\request.py", line 1320, in do_open raise URLError(err)

URLError: < urlopen error [Errno 11004] getaddrinfo failed >

Setting environment variables http_proxy and https_proxy does lead to the same problem.

Is there any way to edit proxy settings in Spyder directly? If not: how do I adjust the proxy in python?

import urllib2
proxy_user='xxx'
proxy_password='xxx'
proxy_ip='proxy.company:8080'
proxy_url = 'http://' + proxy_user + ':' + proxy_password + '@' + proxy_ip
proxy_support = urllib2.ProxyHandler({"http":proxy_url})
opener = urllib2.build_opener(proxy_support,urllib2.HTTPHandler)
urllib2.install_opener(opener)

throws following error

ModuleNotFoundError: No module named 'urllib2'

Thanks in advance, Johnny

Johnny R.
  • 126
  • 1
  • 2
  • 6
  • If you're using Python 3, I think you need to change `urllib2` to `urllib3`. – Carlos Cordoba Oct 05 '17 at 12:32
  • Thank you for your quick response, Carlos! Unfortunately, analogue to urllib2, the program outputs ModuleNotFoundError: No module named 'urllib3' – Johnny R. Oct 05 '17 at 13:20
  • 1
    Found a working solution: not only setting http_proxy for user's environment variable but for system's plus executing Spyder as administrator both is required, but it is working for me! thanks! – Johnny R. Oct 06 '17 at 09:09

1 Answers1

1

Open

  • Anaconda Prompt as Administrator
  • Add proxy settings in conda using command: conda config --set proxy_servers.https "proxy.company.com:8080"

Your proxy settings are now ready to be used in Conda environment. Also, you can run your python code from Conda prompt.

pvy4917
  • 1,768
  • 17
  • 23