# Python - and only Python - can't see the Internet, mostly...

## minnmass

At least so far as I can tell, Python cannot see the Internet, though everything else can.

The most common error message I get from Python scripts is:

 *Quote:*   

> ERROR: unable to download video webpage: <urlopen error [Errno -2] Name or service not known>

 

The only exception to this is Python Ping. This suggests to me that if Python would stick to IPv4, it would work, but that it's trying to use IPv6 for some reason. I have attempted to disable IPv6 on my system, as it just didn't work (virtually nothing would work without special configuration, about two years ago when I decided to give it a whirl on my new system).

 *System Information wrote:*   

> 
> 
> $ python -V
> 
> Python 2.7.2
> ...

 

Everything on my system should be up to date (or, at least, no more than a couple of days old).

I'm at a loss for where to look next; please point me to resources I may have overlooked or been unable to find; googling 'python internet' and 'urlopen error [Errno -2]' and the like haven't gotten me anywhere. I will, of course, post any other reasonable information that may be helpful.

----------

## Hu

What is the output of emerge --info dev-lang/python:2.7 sys-libs/glibc ; zgrep IPV6 /proc/config.gz?  What parameters did the failed Python script use when it received that error?

----------

## minnmass

 *Quote:*   

> 
> 
> $ emerge --info dev-lang/python:2.7 sys-libs/glibc ; zgrep IPV6 /proc/config.gz
> 
> Portage 2.1.10.41 (default/linux/amd64/10.0, gcc-4.5.3, glibc-2.13-r4, 3.0.6-gentoo x86_64)
> ...

 

(As a side note, the concept of /proc/config.gz is awesome, and will be available the next time I need to recompile my kernel anyway; for that alone, I thank you.)

----------

## Hu

That output confirms that the system has been built consistent with your intent to disable IPv6.  What about the Python script itself?  I asked above about the urlopen parameters.

----------

## minnmass

Sorry.

It appears to be any python script: app-portage/mirrorselect, for instance, doesn't work:

```

$ sudo !!

sudo mirrorselect -i

Password: 

* Downloading a list of mirrors...

ERROR: Could not get mirror list. Check your internet connection.

```

Similarly, youtube-dl doesn't work:

```

$ youtube-dl -U

Updating to latest version...

Traceback (most recent call last):

  File "/home/minnmass/scripts/youtube-dl", line 4237, in <module>

    main()

  File "/home/minnmass/scripts/youtube-dl", line 4215, in main

    updateSelf(fd, sys.argv[0])

  File "/home/minnmass/scripts/youtube-dl", line 3838, in updateSelf

    urlh.close()

UnboundLocalError: local variable 'urlh' referenced before assignment

$ youtube-dl --version

2011.10.19

$ youtube-dl http://www.youtube.com/watch?v=$VIDEO

[youtube] Setting language

WARNING: unable to set language: <urlopen error [Errno -2] Name or service not known>

[youtube] $VIDEO: Downloading video webpage

ERROR: unable to download video webpage: <urlopen error [Errno -2] Name or service not known>

```

(In that last example, $VIDEO is a legitimate video ID; the particular video attempted doesn't matter.)

Manually updating to the most current version of youtube-dl (downloaded direct from the source) doesn't fix anything or change anything in the errors generated, save for some line numbers:

```

$ youtube-dl -U

Updating to latest version...

Traceback (most recent call last):

  File "/home/minnmass/scripts/youtube-dl", line 4514, in <module>

    main()

  File "/home/minnmass/scripts/youtube-dl", line 4505, in main

    _real_main()

  File "/home/minnmass/scripts/youtube-dl", line 4479, in _real_main

    updateSelf(fd, sys.argv[0])

  File "/home/minnmass/scripts/youtube-dl", line 4075, in updateSelf

    urlh.close()

UnboundLocalError: local variable 'urlh' referenced before assignment

```

----------

## Hu

I think the youtube-dl authors need to learn about modules.  That file is huge!

After looking at the source, my guess is that urllib.urlopen fails for you, but does so in a way that does not raise an exception.  What is the output of cat /etc/resolv.conf; ls -l /etc/resolv.conf?  Also, please pastebin the output of strace -tt -s4096 youtube-dl -U.

----------

## minnmass

```

$ cat /etc/resolv.conf ; ls -l /etc/resolv.conf 

# Generated by net-scripts for interface eth0

nameserver 192.168.2.1

-rw-r--r-- 1 root root 69 Dec 26 10:42 /etc/resolv.conf

```

Also, in case it matters:

```

$ cat /etc/conf.d/net

# This blank configuration will automatically use DHCP for any net.*

# scripts in /etc/init.d.  To create a more complete configuration,

# please review /etc/conf.d/net.example and save your configuration

# in /etc/conf.d/net (this file :]!).

# config_eth0=( "dhcp" )

 config_eth0="192.168.2.10/24"

 routes_eth0="default via 192.168.2.1"

 dns_servers_eth0="192.168.2.1"

modules="wpa_supplicant"

```

That last line isn't necessary (it's a wired connection).

The 2.3M output (all 3970 lines of it) of strace are available here, via DropBox (Pastebin's limit is 500k for non-Pro users).

```
$ file strace_output.txt 

strace_output.txt: ASCII English text, with very long lines, with CRLF, LF line terminators, with escape sequences

```

----------

## calibumm

I'd had the exact same issue, specifically with youtube-dl after I attempted to install a python package called buildbot but later removed it.  After the removal,

It looks to have mis-configured something with certain python modules, namely urllib.

I added a few print statements in my youtube-dl script and it fails right before that call to urllib.urlopen and that module is found in 

/usr/lib/python2.7/dist-packages

I wasn't sure if a resolution came about from this thread.

----------

## chris...

Im getting the same issue as well

Doesnt work on groove shark either

It used to work before

----------

