以下print
输出一个copy / pastable Curl命令,该命令在我的终端中按预期工作,服务器以200响应:
print (
"curl 'https://some.domain.com/path"
"?param1=1¶m2=2' "
"-X PUT "
"-H 'Host: foo.domain.com' "
"-H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0' "
"-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' "
"-H 'Accept-Language: en-US,en;q=0.5' "
"-H 'Accept-Encoding: gzip, deflate' "
"-H 'Content-Type: application/json; charset=utf-8' "
"-H 'SomeToken: a16e7f17df3f4bdb982dac9593a941ab' "
"-H 'Cookie: "
"cookie1=value1; "
"' "
"-H 'Connection: keep-alive' "
"--data "
'\'{"name":"blubb_234","someId":1234,"someVal":"...",'
'"yoyoyo":"","cool":{"id":7},"price":"125.5","currency":"EUR"}\''
)
以下请求命令是我可以直接翻译上面的Curl命令。但在这种情况下,服务器响应500:
res = requests.request("PUT",
("https://some.domain.com/path"
"?param1=1¶m2=2"),
headers={
"Host": "foo.domain.com",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json; charset=utf-8",
"SomeToken": "a16e7f17df3f4bdb982dac9593a941ab",
"Connection": "keep-alive"
},
data={
"name": "blubb_234",
"someId": 1234,
"someVal": "...",
"yoyoyo": "",
"cool": {"id":7},
"price":"125.5",
"currency":"EUR"
},
cookies={"cookie1":"value1"}
)
知道可能出现什么问题吗?
> requests.__version__
2.2.1
> sys.version
'2.7.6 (default, Jun 22 2015, 17:58:13) \n[GCC 4.8.2]'