为了账号安全,请及时绑定邮箱和手机立即绑定

按照老师的代码敲的,为什么会报错?求大神解答

代码:

from urllib.request import urlopen
from urllib.request import Request
from urllib import parse
req = Request("http://www.thsrc.com.tw/tw/TimeTable/SearchResult")
postData = parse.urlencode([
    ("StartStatio","2f940836-cedc-41ef-8e28-c2336ac8fe68"),
    ("EndStation","977abb69-413a-4ccf-a109-0272c24fd490"),
    ("SearchDate","2017/06/11"),
    ("SearchTime","13:00"),
    ("SearchWay","DepartureInMandarin")
])
req.add_header("Origin","http://www.thsrc.com.tw")
req.add_header("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")
resp = urlopen(req, data=postData.encode('utf-8'))
print(resp.read().decode("utf-8"))

错误:

Fatal Python error: Py_Initialize: can't initialize sys standard streams

Traceback (most recent call last):

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/io.py", line 52, in <module>

  File "/Users/Yvette/PycharmProjects/2017/201705/abc.py", line 1, in <module>

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 84, in <module>

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/base64.py", line 9, in <module>

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 122, in <module>

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/enum.py", line 2, in <module>

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/types.py", line 171, in <module>

  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/functools.py", line 20, in <module>

ImportError: cannot import name 'get_cache_token'


正在回答

1 回答

代码我电脑python3.6能运行成功

是不是没添加python的path?

0 回复 有任何疑惑可以回复我~
#1

iamYvette 提问者

我之前找到了原因。脚本对应文件夹下有我用jupyter notebook创建的.ipynb就发生了这个问题。我一删除该ipynb文件或者将其移至其他文件夹就没问题了。但我还不太明白造成这个问题的原因是什么。因为使用pycharm创建的jupyter就没问题。。。通过终端创建的就发生问题
2017-06-28 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

按照老师的代码敲的,为什么会报错?求大神解答

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信