该服务是基于.net的服务。以下是python代码
URL = 'http://vp-testprocessor-service-bdp-dev.dev.xxxxxxxxxxxxxx.com/api/testprocessor/v1/testprocessors/requests'
headers = {'Authorization': 'Bearer 00000000-0000-0000-adb2-3087bcbcdaf7',
'Accept': 'applicaiton/json',
'Content-Type': 'audio/x-wav;type=alaw;bit=16;rate=8000;channels=1',
'User-Agent': 'Mozilla/5.0 AppleWebkit/537.36 Chrome/41.0.2272.101 Safari/537.36'}
session = requests.Session()
with open(input_file, 'rb') as fd:
data = fd.read()
request = requests.Request('POST', url, data = data, headers = headers)
prepped = session.prepare_request(request)
response = session.send(prepped, allow_redirects=False)
这是python3的输出。
DEBUG:urllib3.connectionpool:06-13 07:59 Starting new HTTP connection (1): vp-testprocessor-service-bdp-dev.dev.xxxxxxxxxxxxxx.com
DEBUG:urllib3.connectionpool:06-13 07:59 http://vp-testprocessor-service-bdp-dev.dev.xxxxxxxxxxxxxx.com:80 "POST /api/testprocessor/v1/testprocessors/requests HTTP/1.1" 400 0
这是curl中对应的命令
curl -X POST -i http://vp-testprocessor-service-bdp-dev.dev.xxxxxxxxxxxxxx.com/api/testprocessor/v1/testprocessors/requests -H "Accept:application/json" -H "Content-Type:audio/x-wav;type=alaw;bit=16;rate=8000;channels=1" -H "Authorization:Bearer 00000000-0000-0000-adb2-3087bcbcdaf7" --data-binary @test.WAV
响应是预期的响应:
HTTP/1.1 202 Accepted
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Location: v1/testprocessors/requests/cjid8zvy905sd015mqzhk3tex
Vary: Accept
Server: nginx/1.13.9
Set-Cookie: ApplicationGatewayAffinity=aec8bf4924904624c014f771c7c7d5052d5ca7537afccc9caa42d74a1f7e0023;Path=/;Domain=vp-testprocessor-service-bdp-dev.dev.xxxxxxxxxxxxxx.com
Date: Wed, 13 Jun 2018 15:06:11 GMT
{"status":"created","id":"cjid8zvy905sd015mqzhk3tex",...}
这是python请求的wireshark跟踪:
1 0.000000000 192.168.0.75 55.555.555.555 TCP 74 38418 → 80 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=2153419701 TSecr=0 WS=128
2 0.101349932 55.555.555.555 192.168.0.75 TCP 74 80 → 38418 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len=0 MSS=1440 WS=256 SACK_PERM=1 TSval=1248614227 TSecr=2153419701
3 0.101404983 192.168.0.75 55.555.555.555 TCP 66 38418 → 80 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=2153419803 TSecr=1248614227
4 0.101499143 192.168.0.75 55.555.555.555 TCP 499 38418 → 80 [PSH, ACK] Seq=1 Ack=1 Win=29312 Len=433 TSval=2153419803 TSecr=1248614227 [TCP segment of a reassembled PDU]
5 0.101595314 192.168.0.75 55.555.555.555 HTTP 256 POST /api/testprocessor/v1/testprocessors/requests HTTP/1.1 (audio/x-wav)
6 0.219204806 55.555.555.555 192.168.0.75 TCP 66 80 → 38418 [ACK] Seq=1 Ack=624 Win=263424 Len=0 TSval=1248614344 TSecr=2153419803
7 0.232013694 55.555.555.555 192.168.0.75 HTTP 347 HTTP/1.1 400 Bad Request
这是curl请求的相应跟踪
1 0.000000000 192.168.0.75 55.555.555.555 TCP 74 38400 → 80 [SYN] Seq=0 Win=29200 Len=0 MSS=1460 SACK_PERM=1 TSval=2153267280 TSecr=0 WS=128
2 0.102793917 55.555.555.555 192.168.0.75 TCP 74 80 → 38400 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len=0 MSS=1440 WS=256 SACK_PERM=1 TSval=1248461807 TSecr=2153267280
3 0.102863788 192.168.0.75 55.555.555.555 TCP 66 38400 → 80 [ACK] Seq=1 Ack=1 Win=29312 Len=0 TSval=2153267383 TSecr=1248461807
4 0.102977867 192.168.0.75 55.555.555.555 HTTP 576 POST /api/testprocessor/v1/testprocessors/requests HTTP/1.1 (audio/x-wav)
5 0.273885394 55.555.555.555 192.168.0.75 TCP 66 80 → 38400 [ACK] Seq=1 Ack=511 Win=263424 Len=0 TSval=1248461978 TSecr=2153267383
6 0.601893345 55.555.555.555 192.168.0.75 TCP 613 80 → 38400 [PSH, ACK] Seq=1 Ack=511 Win=263424 Len=547 TSval=1248462306 TSecr=2153267383 [TCP segment of a reassembled PDU]
7 0.601961170 192.168.0.75 55.555.555.555 TCP 66 38400 → 80 [ACK] Seq=511 Ack=548 Win=30336 Len=0 TSval=2153267882 TSecr=1248462306
8 0.601975534 55.555.555.555 192.168.0.75 HTTP 71 HTTP/1.1 202 Accepted (application/json)
我有几个问题,1.有没有办法从urllib3获得更多的调试信息? 2.我可以做些什么来模仿curl的行为? 3.我可以生成哪些信息来帮助调试服务器端?
谢谢。
发布于 2018-06-14 07:08:53
我在头文件中看到了拼写错误,应该是python代码中的'Accept':'application/json‘,而不是'Accept':'applicaiton/json’
https://stackoverflow.com/questions/50841042
复制相似问题