urllib.error.URLError:

后端 未结 4 1331
-上瘾入骨i
-上瘾入骨i 2020-11-29 12:09

(Python 3.4.2) I\'ve got a weird error when I run \'urllib.request.urlopen(url)\' inside of a script. If I run it directly in the Python interpreter, it works fine, but not

相关标签:
4条回答
  • 2020-11-29 12:50

    people who encountered the error ValueError: unknown url type: 'http or ValueError: unknown url type: b'http

    while opening some url like below with urllib.request.Request 'http://localhost/simple_form/insert.php'

    just change localhost to 127.0.0.1

    looks like Request method is looking for a domain.something in url

    0 讨论(0)
  • 2020-11-29 12:51

    I figured it out. My url had a : in it, and urllib cannot use that character. I replaced it with %3A and now it's working. Web browsers usually convert : to %3A automatically, but urllib requires it to be converted first.

    0 讨论(0)
  • 2020-11-29 12:54

    You should use urllib.parse.urlencode(), urllib.parse.urljoin(), etc functions to construct urls instead of manually joining the strings. It would take care of : -> %3A conversion e.g.:

    >>> import urllib.parse
    >>> urllib.parse.quote(':')
    '%3A'
    
    0 讨论(0)
  • 2020-11-29 13:08

    may due to openssl-devel if you do not install it.

    yum list installed|grep openssl
    

    install it and try again after make.

    sudo yum install openssl-devel
    ./configure
    make
    
    0 讨论(0)
提交回复
热议问题