POST request works in Postman, but not in Python Requests (200 response with robot detection)

后端 未结 2 871
囚心锁ツ
囚心锁ツ 2021-02-05 22:10

I have a POST request that works perfectly with both Postman an cURL (it returns a JSON blob of data). However, when I perform the exact same request with Python\'s Requests lib

2条回答
  •  时光说笑
    2021-02-05 22:39

    I had a similar issue that I was able to resolve by sending a cookie in the request. Try this:

    ...
    my_cookie = {"Cookie": "cookie text..."}
    
    s = requests.Session()
    response_raw = s.post(url, json=payload, headers=headers, cookies=my_cookie)
    print(response_raw)
    print(response_raw.text)
    print(response_raw.content)
    

    You can grab the cookie from the Network tab in the browser's Dev Tools console in the Request Headers section. It sounds like you may also be able to get the cookie using Python's CookieJar lib.

提交回复
热议问题