POST request working with cURL in command line, but not working properly when used with Python's requests library

fbald 46 Reputation points
2022-07-21T21:45:06.47+00:00

I am using the form recognizer REST API and when I use cURL with the command line, I have no issue with the POST and GET requests as I am given the operation location from the POST output to then use in the GET request. However, I am trying to use the tool in bulk, and thus I am using the requests library in python. I am receiving the 202 accepted response, which as I've been reading online seems to be correct with this tool. The issue is that I am getting nothing back in the content of the request and thus I have now operation location to complete the GET request. Am I missing anything? Thanks for the help!

Azure AI Document Intelligence
{count} votes

Answer accepted by question author
  1. romungi-MSFT 49,096 Reputation points Microsoft Employee Moderator
    2022-07-25T05:33:40.923+00:00

    @fbald Could you print the response.headers field? This should give you the operation location.

    224242-image.png

    If an answer is helpful, please click on 130616-image.png or upvote 130671-image.png which might help other community members reading this thread.


1 additional answer

Sort by: Most helpful
  1. David Broggy 6,776 Reputation points MVP Volunteer Moderator
    2022-07-22T05:40:50.8+00:00

    hi fbald,
    Here's a basic python script which includes a POST request.
    Does this syntax help at all?

    !/usr/bin/env python

    import requests

    url = 'https://www.example.com/post'

    payload = {

    'key1': 'value1',

    'key2': 'value2'

    }

    headers = {

    'Content-Type': 'application/x-www-form-urlencoded'

    }

    r = requests.post(url, data=payload, headers=headers)

    print(r.text)


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.