Python库执行

2024-03-29 15:36:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了这个python库,它有一个uses urllib和urllib2函数,但是当我从pythonshell执行lib的函数时,我得到了这个错误

>>> from sabermanlib import geturl
>>> geturl("roblox.com","ggg.html")

Traceback (most recent call last):
  File "<pyshell#11>", line 1, in <module>
    geturl("roblox.com","ggg.html")
  File "sabermanlib.py", line 21, in geturl
    urllib.urlretrieve(Address,File)
  File "C:\Users\Andres\Desktop\ddd\Portable Python 2.7.5.1\App\lib\urllib.py", line 94, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook, data)
  File "C:\Users\Andres\Desktop\ddd\Portable Python 2.7.5.1\App\lib\urllib.py", line 240, in retrieve
    fp = self.open(url, data)
  File "C:\Users\Andres\Desktop\ddd\Portable Python 2.7.5.1\App\lib\urllib.py", line 208, in open
    return getattr(self, name)(url)
  File "C:\Users\Andres\Desktop\ddd\Portable Python 2.7.5.1\App\lib\urllib.py", line 463, in open_file
    return self.open_local_file(url)
  File "C:\Users\Andres\Desktop\ddd\Portable Python 2.7.5.1\App\lib\urllib.py", line 477, in open_local_file
    raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the file specified: 'roblox.com'
>>>

下面是我制作的lib的代码:

^{pr2}$

编辑2

我不明白为什么在执行python shell时会出现此错误:

geturl(Address,File)

Tags: inpyappurlliblineopenurllib
1条回答
网友
1楼 · 发布于 2024-03-29 15:36:26

你不想urllib.url检索. 这需要一个类似文件的对象。相反,你想urllib.urlopen公司名称:

>>> help(urllib.urlopen)
urlopen(url, data=None, proxies=None)
    Create a file-like object for the specified URL to read from.

此外,如果要下载并保存文档,则需要更健壮的geturl函数:

^{pr2}$

相关问题 更多 >