追溯(最近一次呼叫最近):<模块>中的文件“ <stdin>”,第1行

时间:2018-10-29 03:01:33

标签: python python-2.7

我只输入了一些代码:

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’

1 个答案:

答案 0 :(得分:0)

您需要在"http://"的前面放置"https://"URL,因此请尝试:

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

或者:

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

注意:请使用'"代替