urllib.request.Request - 意外关键字参数'方法'

时间:2013-12-18 02:58:39

标签: python methods request urllib

尝试使用method参数here会产生以下错误。

Python 3.2.3 (default, Sep 25 2013, 18:22:43)
>>> import urllib.request as r
>>> r.Request('http://example.com', method='POST')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got an unexpected keyword argument 'method'
>>>

无论我搜索的是什么/哪里,我似乎无法找到问题的解决方案。

1 个答案:

答案 0 :(得分:3)

您正在查看Python 3.3的文档但运行Python 3.2。在Python 3.2中,Request初始值设定项没有method参数:http://docs.python.org/3.2/library/urllib.request.html#urllib.request.Request

FWIW取决于您提出的请求类型(例如,如果请求包含正文)urllib将自动使用适当的方法(即POST)。如果你需要提出更专业的请求,例如HEAD,你需要深入挖掘一下。 SO上有其他答案可以帮助解决这个问题。

相关问题