1

I need help making the following Curl request in Python:

curl --data "username=USERNAME&password=PASSWORD" --header "Authorization: Basic Y2xvdWQtYXBp" -X POST "https://ApiCallUrl/auth/token?grant_type=password" --insecure

I have the following code:

url = 'https://fakepath'
data = "username=velocity_169234&password=velocity_69234"
header = {'Authorization': b'Basic' + b64encode(('cloud-api').encode('utf-8'))}
data = urlencode(dict(username='USERNAME',password='PASSWORD')).encode('ascii')

response = urlopen(Request(url, data, header))
print(response.info())

How do I add the --insecure flag?

I am getting this error

    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)>
Chris Johnson
  • 279
  • 2
  • 5
  • 10

1 Answers1

1

curl
-k, --insecure
(SSL) This option explicitly allows curl to perform "insecure" SSL connections and transfers.
All SSL connections are attempted to be made secure by using the CA certificate bundle installed by default.
All connections considered "insecure" will fail unless -k/--insecure is used.


requests Requests can also ignore verifying the SSL certificate if you set verify to False:

requests.get('https://kennethreitz.org', verify=False)
<Response [200]>

By default, verify is set to True. Option verify only applies to host certs.

urlopen don't have such a parameter.

Note: Disable Certificate Verification is a Security Risk!

stovfl
  • 14,998
  • 7
  • 24
  • 51