按照老師的代碼敲的,為什么會(huì)報(bào)錯(cuò)?求大神解答
代碼:
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"))
錯(cuò)誤:
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'
2017-06-14
代碼我電腦python3.6能運(yùn)行成功
是不是沒(méi)添加python的path?