Equivalent of python Curl

Asked

Viewed 3,009 times

2

I was learning to use API’s from websites to a project, and right at the beginning I had difficulties and had to ask.

This was the example of the use of API to test credentials on the site, I believe it is C++:

curl -u user:password https://myanimelist.net/api/account/verify_credentials.xml

The problem is that I started learning now and was by Python 3, then I have no idea what the command does, let alone an equivalent in Python.

After a few seconds I thought I’d wear something with the RobotBrowser or urllib, but I’m not sure if it’s right.

1 answer

6


You can use the Requests: HTTP for Humans to consume some service from an API or make common requests.

Take an example:

>>> import requests 

>>> r = requests.get("https://myanimelist.net/api/account/verify_credentials.xml", auth=('usuario', 'senha'))    
>>> r.text

Answer:

<?xml version="1.0" encoding="UTF-8"?>
<user>
   <id>123456</id>
   <username>gato</username>
</user>

You can consult some ways to install requests if you do not have.

Learn more on Requests.

  • helped a lot, thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.