urllib.request.urlopen:ValueError:未知的url类型

urllib.request.urlopen:ValueError:未知的url类型

问题描述:

我有一个长期存在的问题urllib.request。我做什么:urllib.request.urlopen:ValueError:未知的url类型

wahlrecht = urllib.parse.quote("http://www.wahlrecht.de/umfragen/") 
page = urllib.request.urlopen(url) 

下面是完整的回溯,我得到:

Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
    File "/Users/d069049/Documents/BCCN/Predictor/Backend/wahlrecht_polling_firms.py", line 72, in get_tables 
    page = urllib.request.urlopen(wahlrecht) 
    File "/Users/d069049/anaconda/envs/bccn2017/lib/python3.6/urllib/request.py", line 223, in urlopen 
    return opener.open(url, data, timeout) 
    File "/Users/d069049/anaconda/envs/bccn2017/lib/python3.6/urllib/request.py", line 511, in open 
    req = Request(fullurl, data) 
    File "/Users/d069049/anaconda/envs/bccn2017/lib/python3.6/urllib/request.py", line 329, in __init__ 
    self.full_url = url 
    File "/Users/d069049/anaconda/envs/bccn2017/lib/python3.6/urllib/request.py", line 355, in full_url 
    self._parse() 
    File "/Users/d069049/anaconda/envs/bccn2017/lib/python3.6/urllib/request.py", line 384, in _parse 
    raise ValueError("unknown url type: %r" % self.full_url) 
ValueError: unknown url type: 'http%3A//www.wahlrecht.de/umfragen/' 
+1

嗯,嗯...你为什么在打开它之前引用网址?当然这会使它失效...... –

你解析:仿佛它指定参数时,你需要打开URL引用没有它。 否则,你试图打开http%3A 以下行创建您的问题

wahlrecht = urllib.parse.quote("http://www.wahlrecht.de/umfragen/") 

如果将其更改为

wahlrecht = "http://www.wahlrecht.de/umfragen/" 

它应该工作