python3 url错误未知url类型http
我正在尝试使用urllib.request.urlretrieve和多处理模块下载一些文件并对它们进行处理。但是,每次我尝试运行我的程序时,都会出现以下错误:python3 url错误未知url类型http,python,python-3.x,urllib,Python,Python 3.x,Urllib,我正在尝试使用urllib.request.urlretrieve和多处理模块下载一些文件并对它们进行处理。但是,每次我尝试运行我的程序时,都会出现以下错误: multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "/usr/lib/python3.4/multiprocessing/pool.py", line 119, in worker result = (True,
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib/python3.4/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/usr/lib/python3.4/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "./thumb.py", line 13, in download_and_convert
filename, headers = urlretrieve(url)
File "/usr/lib/python3.4/urllib/request.py", line 186, in urlretrieve
with contextlib.closing(urlopen(url, data)) as fp:
File "/usr/lib/python3.4/urllib/request.py", line 161, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.4/urllib/request.py", line 463, in open
response = self._open(req, data)
File "/usr/lib/python3.4/urllib/request.py", line 486, in _open
'unknown_open', req)
File "/usr/lib/python3.4/urllib/request.py", line 441, in _call_chain
result = func(*args)
File "/usr/lib/python3.4/urllib/request.py", line 1252, in unknown_open
raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: http>
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "./thumb.py", line 27, in <module>
pool.map(download_and_convert, enumerate(csvr))
File "/usr/lib/python3.4/multiprocessing/pool.py", line 260, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "/usr/lib/python3.4/multiprocessing/pool.py", line 599, in get
raise self._value
urllib.error.URLError: <urlopen error unknown url type: http>
我不知道为什么会出现这个错误。可能是因为我在使用多重处理吗?如果有人能帮助我,我将不胜感激
编辑:这是它尝试处理的第一个url,如果我更改它,它不会更改错误。检查此代码段
>>> import urllib.parse
>>> urllib.parse.quote(':')
'%3A'
如您所见,urllib对“:”字符的解释很奇怪。巧合的是,你的程序挂断了
请尝试
urllib.parse.urlencode()
,这将使您走上正确的轨道。检查此代码段
>>> import urllib.parse
>>> urllib.parse.quote(':')
'%3A'
如您所见,urllib对“:”字符的解释很奇怪。巧合的是,你的程序挂断了
请尝试
urllib.parse.urlencode()
,这将使您走上正确的道路。在从注释中获得一些帮助后,我找到了解决方案。问题似乎是csv模块在字节顺序标记(BOM)上出错。我可以通过按建议使用encoding='utf-8-sig'
打开文件来修复它。在从注释中获得一些帮助后,我找到了解决方案。问题似乎是csv模块在字节顺序标记(BOM)上出错。我可以按照建议用encoding='utf-8-sig'
打开文件来修复它。你说,“它似乎阻塞的url是…”。你能核实一下吗?我在except块中看到一个打印(url)
,但在您的问题中没有看到这个输出。如果将包含该URL的行隔离在单独的文件中,是否可以重现错误?你能在你的问题中发布那一行吗?是的,这是except块中打印输出的行。我还应该提到,这是我处理的文件中的第一个URL,如果我删除它,它会给我下一个URL带来相同的错误。对于给定的URL,它对我有效,使用urllib.request import urlretrieve中的一个简单;urlretrieve(“http://phytoimages.siu.edu/users/vitt/10_27_06_2/Equisetumarvense.JPG)
。所以一定是出了什么问题。你能做一个打印(repr(url))
?嗯,它给我'\ufeffhttp://phytoimages.siu.edu/users/vitt/10_27_06_2/Equisetumarvense.JPG“
。不知道这是怎么回事。你说,“它似乎被扼杀的网址是……”。你能核实一下吗?我在except块中看到一个打印(url)
,但在您的问题中没有看到这个输出。如果将包含该URL的行隔离在单独的文件中,是否可以重现错误?你能在你的问题中发布那一行吗?是的,这是except块中打印输出的行。我还应该提到,这是我处理的文件中的第一个URL,如果我删除它,它会给我下一个URL带来相同的错误。对于给定的URL,它对我有效,使用urllib.request import urlretrieve中的一个简单;urlretrieve(“http://phytoimages.siu.edu/users/vitt/10_27_06_2/Equisetumarvense.JPG)
。所以一定是出了什么问题。你能做一个打印(repr(url))
?嗯,它给我'\ufeffhttp://phytoimages.siu.edu/users/vitt/10_27_06_2/Equisetumarvense.JPG“
。不知道这是怎么回事。你说,“它似乎被扼杀的网址是……”。你能核实一下吗?我在except块中看到一个打印(url)
,但在您的问题中没有看到这个输出。如果将包含该URL的行隔离在单独的文件中,是否可以重现错误?你能在你的问题中发布那一行吗?是的,这是except块中打印输出的行。我还应该提到,这是我处理的文件中的第一个URL,如果我删除它,它会给我下一个URL带来相同的错误。对于给定的URL,它对我有效,使用urllib.request import urlretrieve中的一个简单;urlretrieve(“http://phytoimages.siu.edu/users/vitt/10_27_06_2/Equisetumarvense.JPG)
。所以一定是出了什么问题。你能做一个打印(repr(url))
?嗯,它给我'\ufeffhttp://phytoimages.siu.edu/users/vitt/10_27_06_2/Equisetumarvense.JPG“
。不知道那是怎么来的,我不知道那对我有什么帮助。我只是想在某个url上获取文件。我看不出这对我有什么帮助。我只是想在某个url上获取文件。我看不出这对我有什么帮助。我只是想从某个url获取文件。