您将要使用urllib2停止。 以下是在堆栈溢出中找到的示例。
我不知道我为什么要犯错误。
以下是我代码的摘录。 import urllib2
导入JSON
内容_ header={ ' content-type ' : ' application/JSON ',
' accept ' : ' application/vnd.error JSON,application/json ',
'接受版本' : ' 1.0 ' }
baseURL='http://some/put/url/'
f=open('somefile ',' r ' ) )。
data=JSON.loads(f.read ) )
request=urllib2. request (URL=base URL,data=JSON.dumps ) JSONobj ),headers=content_header ) )。
request.get _ method=lambda : ' put ' # ifiremovethislinethenthepostworksfine。
response=urllib2. urlopen (request )
打印response.read (
如果删除了我尝试设置的跌倒选项,它将宣布其发现,但如果尝试将get_方法设置为查看跌倒,它将出错。
为了避免REST服务出现问题,尝试使用cURL运行PUT。 运作良好。