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
Use
requests.get(url, auth=(username, password))
See the section on Basic Authentication in the requests documentation.
Related
I wanna send a curl post request in python. But I can't install any lib like 'request'. I could send POST request like following example :
curl -H "Content-Type: application/json" -X POST -d {\"username\":\"myusername\",\"password\":\"mypassword\"} https://example.com/login
I need equal code as the above in python2. Then, i must read what it returns. I'm working on Windows 10.
Write a curl command in a way that it can work in the shell and then execute the command in the shell.
This way you don't need the requests package.
import os
command = "curl -u {username}:{password} [URL]"
os.system(command)
I have a curl command. I want to fetch the response after executing it in python 3.
curl https://api.abc.com/targets/targetID\
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: JWT PROBELY_AUTH_TOKEN"
How can I execute the script in Python and get the response ?
try this:
import requests
url = 'https://api.abc.com/targets/AxthamE0v3E-/scans/S6dOMPj8SsoH/'
r = requests.get(url,headers={"Content-Type": "application/json","Authorization": "JWT PROBELY_AUTH_TOKEN"})
print(r.text)
If you need to perform a request, you can use the library requests.
You can easily install it with pip install requests
https://www.w3schools.com/python/module_requests.asp
You can use this link to see how to work with this library
I want to run Following Curl Command in Python and I was trying the requests command of python but I am not getting the proper results.
curl -v ftp://ftp.abc.com/File.txt --socks5-hostname socks.abc.com:PORT --user username:password -O
You can use subprocess.
import subprocess
result = subprocess.run(["curl", "-v", "ftp://ftp.abc.com/File.txt --socks5-hostname socks.abc.com:PORT --user username:password -O"], capture_output=True)
print(result.stdout)
I'm not into web development but this looks like something the requests module should be able to handle.
r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
r.status_code
https://requests.readthedocs.io/en/master/
I'm using a proxy which has self-signed SSL certificate.
curl has a --proxy-insecure option which not check ssl of proxy for validation.
curl -x https://some.proxy.com --proxy-insecure -I https://www.somewebsite.now
I want to covert my code in python,
so is there any substitution for --proxy-insecure in python?
with requests:
pip3 install requests
and then:
import requests
requests.get('https://www.somewebsite.now', proxies={'https': 'https://some.proxy.com'}, verify=False)
I am trying to connect to an API with kerberos authentification.
With CURL its just simple:
curl -k --negotiate -u : "https://MY-API-SERVER" -i
With Python I just can't find how to do the samething.
What I tried so far is:
from requests_kerberos import HTTPKerberosAuth, REQUIRED
kerberos_auth = HTTPKerberosAuth(mutual_authentication=REQUIRED,force_preemptive=True)
r = requests.get("https://MY-API-SERVER", auth=kerberos_auth,verify=False, headers={'username':'xxxxx', 'password':'yyyyy'})