【问题标题】:Traceback (most recent call last): File "<stdin>", line 1, in <module>回溯(最后一次调用):文件“<stdin>”,第 1 行,在 <module>
【发布时间】:2019-04-01 22:52:57
【问题描述】:

我只是输入了一些代码:

import urllib
response=urlib.urlopen(“www.baidu.com”)

比错误码:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 87, in urlopen
    return opener.open(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 213, in open
    return getattr(self, name)(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 469, in open_file
    return self.open_local_file(url)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 483, in open_local_file
    raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] No such file or directory: ‘www.baidu.com’

【问题讨论】:

  • 如果您将“http://”或“https://”放在您的 URL 前会有什么变化吗?
  • www.baidu.com 不是网址。你需要像http://www.baidu.com这样的协议。
  • 你还在第二行拼错了urllib...

标签: python python-2.7


【解决方案1】:

URL前面需要有"http://""https://",所以试试:

import urllib
response=urlib.urlopen('http://www.baidu.com')

或者:

import urllib
response=urlib.urlopen('https://www.baidu.com')

注意:使用'" 代替

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-27
    • 2022-10-13
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    • 2021-12-16
    • 2022-01-10
    相关资源
    最近更新 更多