1

good day! I need to send a request via the api to the https server. the documentation describes that this must be done via curl. example request:

enter image description here

everything works out through curl. the request is sent, the response comes ok.

but if I try to send the same request with a python script, I get a 401 error.

here is my code.

import requests


def main():
    token = 'my_token'
    # url = 'https://api-ip.fssp.gov.ru/api/v1.0/'
    url = 'https://api-ip.fssp.gov.ru/api/v1.0/search/physical'
    region = '48'
    lastname = 'Иванов'
    firstname = 'Валерий'
    secondname = 'Викторович'
    birthdate = '02.07.1970'

    data = {
    'token': token,
    'region': region,
    'lastname': lastname,
    'firstname': firstname,
    'birthdate': birthdate,
    'secondname': secondname
    }

    response = requests.get(url=url, data=data)

    print(response.status_code)


if __name__ == '__main__':
    main()

here is the content of the response from the server

b'{"status":"error","code":401,"exception":"token not exist","response":[]}'

What am I doing wrong?

5
  • 1
    I wanted to start working on this by verifying that everything works via curl. But then you made things difficult by only including a screenshot. Commented Feb 23, 2022 at 10:43
  • 2
    Don't upload images of code or errors Commented Feb 23, 2022 at 10:46
  • You're also passing more parameters than in the curl command you say works - and the 401 code suggests that you may have made a mistake in copying / encoding / .. the token, because it means 'unauthorised'. It's also possible that the site simply doesn't like that you're coming in using Python and you may need to pretend being another User-agent. I don't feel like trying my luck on api-ip.fssp.gov.ru/api/v1.0/search/physical Commented Feb 23, 2022 at 10:50
  • That's still an image, by the way - if you'd take the time to see why people don't like images, not being able to copy paste ranks pretty high. Commented Feb 23, 2022 at 10:52
  • You're not passing the required API key Commented Feb 23, 2022 at 11:12

1 Answer 1

1

Try using the params argument instead of data to URL encode the values:

    response = requests.get(url=url, params=data)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.