简体   繁体   中英

convert fiddler post to python request.post

i am using fiddler3 to capture the data flow during my browser, and i want to make a post using python request modulus.

The post information i could find in Fiddler is:

URL:
https://shippingmanager.bpost.be/ShmFrontEnd/internal/110492/orders
Request Method: POST
Request Header:
Host: shippingmanager.bpost.be
Connection: keep-alive
Content-Length: 586
Origin: https://shippingmanager.bpost.be
language: en
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36
Content-Type: application/json;charset=UTF-8
Accept: application/json, text/plain, */*
token: c087c667-7580-43b9-8bce-0c25f8377b8a
accountId: 110492
Referer: https://shippingmanager.bpost.be/ShmFrontEnd/start
Accept-Encoding: gzip, deflate, br
Accept-Language: en,en-US;q=0.9,zh-CN;q=0.8,zh;q=0.7,it;q=0.6,it-IT;q=0.5,it-CH;q=0.4
Cookie: JSESSIONID=3098DB975635FC531C284F1F5E1122D8.shm-v001330-frontend-pr-node4; _acl=YWRtaW46bm8=; _ga=GA1.3.809755681.1542326259; _gid=GA1.3.1523310150.1542326259

Request body:
{"reference":"1542362877BW24387","costCenter":"","totalPriceInEuroCent":"11000","weight":"2000","deliveryMethodId":7,"orderLines":[],"customer":{"firstName":"xhibg","lastName":"cdegg","company":"1988","street":"9 oxford street","streetNumber":"rm 3","box":"02138","postalCode":"02138","city":"cambridge","country":"US","language":"en","email":"jbgrveneio@foxairmail.com","phoneNumber":"8088254427","privateAddress":"true"},"selectedServices":[],"priceOverrides":[{"priceZone":"Z3","price":3400}],"extra":"","extraSecure":"","shopHandlingInstruction":"","additionalCustomerReference":""}

If i tried to compose a POST using fiddler, the Response looks good. However, i got errors using Python Request from the Server with a 400 status code. Here is my python code:

import requests
import bs4

post_url = ' https://shippingmanager.bpost.be/ShmFrontEnd/internal/110492/orders'  

headers ={"Host": "shippingmanager.bpost.be",
"Connection": "keep-alive",
"Content-Length": "586",
"Origin": "https://shippingmanager.bpost.be",
"language": "en",
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Content-Type": "application/json;charset=UTF-8",
"Accept": "application/json, text/plain, */*",
"token": "c087c667-7580-43b9-8bce-0c25f8377b8a",
"accountId": "110492",
"Referer": "https://shippingmanager.bpost.be/ShmFrontEnd/start",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en,en-US;q=0.9,zh-CN;q=0.8,zh;q=0.7,it;q=0.6,it-IT;q=0.5,it-CH;q=0.4",
}
cookies = {"JSESSIONID":"JSESSIONID=3098DB975635FC531C284F1F5E1122D8.shm-v001330-frontend-pr-node4",
          "_acl":"YWRtaW46bm8=",
          "_ga":"GA1.3.809755681.1542326259",
         "_gid":"A1.3.1523310150.1542326259"
          }

data = {"reference":"1542362877BW24387",
    "costCenter":"",
    "totalPriceInEuroCent":"11000",
    "weight":"2000",
    "deliveryMethodId":7,
    "orderLines":[],
    "customer"{"firstName":"xhibg","lastName":"cdegg","company":"1988","street":"9 oxford street","streetNumber":"rm 3","box":"02138","postalCode":"02138","city":"cambridge","country":"US","language":"en","email":"jbgrveneio@foxairmail.com","phoneNumber":"8088254427","privateAddress":"true"},
    "selectedServices":[],
    "priceOverrides":[{"priceZone":"Z3","price":3400}],
    "extra":"",
    "extraSecure":"",
    "shopHandlingInstruction":"",
    "additionalCustomerReference":""
    }

r = requests.post(post_url,headers=headers,data = data,cookies=cookies)
print (r.status_code)
soup = bs4.BeautifulSoup(r.text,'html.parser')
print (soup)

I am wondering, probably i did not format the request body well, but I have not idea how to fix.

You have an extra space at your url, this is probably it There is a cool fiddler extension i wrote to transform transcation to python request

https://github.com/yaronav/fiddlerRequestify

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM