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)
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 have a curl command that works and gives me back the JSON.
Curl command:
curl -sS -k -L -H "Authorization: bearer <token>" -X GET https://IP:PORT/api/v1/namespaces
I tried with requestsand pycurl modules which I found in the other posts but no luck.
Can anyone help me with finding the equivalent in python???
We can do this with requests like this:
import requests
header = {'Authorization': 'bearer <token>'}
resp = requests.get("https://IP:PORT/api/v1/namespaces",
headers = header,
verify=False)
print(resp.status_code)
print(resp.text)
The -H switch behaviour is replicated by sending a header
The -L switch behaviour is replicated by specifying verify=False
The -sS and -k are about the behaviour of curl and not relevant here
The -X GET is replicated by using requests.get()
Is there a good way in python to check if a website/url supports http2 and which SSL versions does it support.
What I am looking for is achievable by the use of commands
openssl s_client connect domain:443 nextprotoneg ''
output of this openssl command contains this line : Protocols advertised by server: h2, spdy/3.1, http/1.1 Through which I can figure out the http2 support.
curl -v -o /dev/null --silent https://www.example.com
This line -> TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 in the output of the above command can tell me about the SSL version used.
I don't want to run these commands and parse the output because I feel there should be a better way to do it.
You can use the Hyper lib.
from hyper import HTTPConnection
conn = HTTPConnection('google.com:443')
# If request made over http/1.1 then result will be None
if conn.request('HEAD', '/') is not None:
# Return a string identifying the protocol version used by the current SSL channel
print(conn._sock._sck.version()) # little bit dirty, but work
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.