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

运行报错,求解

按照老师讲的写的代码,报错如下:怎么回事呢?

D:\Python36\python.exe D:/PycharmProjects/urltest/urlpost.py

Traceback (most recent call last):

  File "D:/PycharmProjects/urltest/urlpost.py", line 11, in <module>

    ("SearchWay", "DepartureInMandarin")

TypeError: 'tuple' object is not callable


源代码:

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([
   ("StartStation", "977abb69-413a-4ccf-a109-0272c24fd490"),
   ("EndStation", "9c5ac6ca-ec89-48f8-aab0-41b738cb1814"),
   ("SearchDate", "2017/02/17"),
   ("SearchTime", "19:00")
   ("SearchWay", "DepartureInMandarin")
])
req.add_header("Origin", "http://www.thsrc.com.tw")
req.add_header("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36")
resp = urlopen(req, data=postData.encode("utf-8"))

print(resp.read().decode("utf_8"))



正在回答

1 回答

自己解答一波,是因为漏掉一个逗号。。。

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

举报

0/150
提交
取消

运行报错,求解

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