Connectivity issue with urllib - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: Connectivity issue with urllib (/thread-13772.html) |
Connectivity issue with urllib - ronen1m - Oct-31-2018 Hi, I think I'm having some issues with urllib but I'm not sure what exactly is the problem. While trying a basic code as : import urllib import urllib.request def connected(host='http://www.google.com'): try: urllib.request.urlopen(host) return True except: return False # test print( 'connected' if connected() else 'no internet!' )While running this code through PyScripter or PyCharm I'm getting 'no internet!' message while running under git Bash I'm getting 'connected!' Any idea what could be the difference? This is just a basic test as I'm trying to connect to P4 through p4python and to Rally with pyral. I'm connected through corporate proxy. Thanks! RE: Connectivity issue with urllib - ronen1m - Nov-06-2018 Ok, some more details. Now it doesn't work at all. I'm using PyScripter 3.4.2 (64) and Python 3.6.7 (64) But in anyway, in git bash it does not work at all (getting 'Not Connected' msg) Can anyone help with commands on how to find the problem? Perhaps firewall? proxy? RE: Connectivity issue with urllib - wavic - Nov-06-2018 Run the interpreter, import urllib and try urllib.request.get('https://google.com').getcode() to see if you get 200.If you just want to check for the internet connection there are services which return your public IP. RE: Connectivity issue with urllib - ronen1m - Nov-12-2018 Thank you for your reply. This is the error msg that I'm getting - Traceback (most recent call last): File "Connect2INTERNT.py", line 43, in <module> main() File "Connect2INTERNT.py", line 40, in main urllib.request.get('https://google.com').getcode() AttributeError: module 'urllib.request' has no attribute 'get' RE: Connectivity issue with urllib - wavic - Nov-12-2018 Sorry! My bad. I am using requests for too long. There is not get method but urlopen instead. urllib.request.urlopen('https://google.com').getcode() RE: Connectivity issue with urllib - ronen1m - Nov-13-2018 oh ok :) That didn't work at all... here is the output (copied only the err msg): socket.gaierror: [Errno 11004] getaddrinfo failed urllib.error.URLError: <urlopen error [Errno 11004] getaddrinfo failed> RE: Connectivity issue with urllib - wavic - Nov-13-2018 Perhaps there is some DNS issue. It works for me. In [1]: import urllib In [2]: urllib.request.urlopen('https://google.com').getcode() Out[2]: 200 RE: Connectivity issue with urllib - ronen1m - Nov-22-2018 What checks can I do to see where is the problem? If it is DNS, Security, Firewall... |