Python Forum
Connectivity issue with urllib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Connectivity issue with urllib
#1
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!
Reply
#2
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?
Reply
#3
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.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#4
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'
Reply
#5
Sorry! My bad. I am using requests for too long. Big Grin
There is not get method but urlopen instead.

urllib.request.urlopen('https://google.com').getcode()
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
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>
Reply
#7
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
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#8
What checks can I do to see where is the problem?
If it is DNS, Security, Firewall...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Urllib error wintenrod 3 3,705 Sep-14-2020, 06:18 AM
Last Post: wintenrod

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020