I'm trying to convert a cURL command to python and I'm struggling
curl -I --user username:password https://an.api.on.the.internet/
My current attempt is:
import requests cur = requests.get('https://an.api.on.the.internet', auth='username:password')
Could anyone help me convert it? thanks
Curl Converter automatically generates valid Python code using the Python request library for all provided Curl HTTP headers and Curl data. Enter the Curl command, click Run to execute the command online and check the results. Click Generate Code and select Python to convert the Curl command to Python code.
In Python, cURL transfers requests and data to and from servers using PycURL. PycURL functions as an interface for the libcURL library within Python. Almost every programming language can use REST APIs to access an endpoint hosted on a web server.
Use
requests.get(url, auth=(username, password))
See the section on Basic Authentication in the requests
documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With