Curl Equivalent in python

2

I was learning to use site APIs for a project, and at the beginning I was struggling and needed to ask.

This was the example of using the API to test credentials on the site, I believe it's C ++:

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

The problem is that I started to learn now and it was through Python 3, so I have no idea what the command does, let alone a Python equivalent.

After a few seconds I thought about using something with RobotBrowser or urllib, but I'm not sure if it's right, as I do not want to divert studies from focus, better ask, thank you in advance.

    
asked by anonymous 15.02.2018 / 02:23

1 answer

3

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

See 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 check some ways to install requests if you do not.

Learn more about Requests .

    
15.02.2018 / 02:45