Reputation: 41
I need to run this connamd in Python
curl -v 'https://developer.api.autodesk.com/authentication/v2/token'
-X 'POST'
-H 'Content-Type: application/x-www-form-urlencoded'
-H 'Accept: application/json'
-H 'Authorization: Basic base64_string'
-d 'grant_type=client_credentials'
-d 'scope=data:write data:read bucket:create bucket:delete'
I'm trying this, but I keep getting the error pycurl.error: (3, 'URL rejected: Malformed input to a URL function')
I've tried this script but I keep gettin the error pycurl.error: (3, 'URL rejected: Malformed input to a URL function'):
import os
import base64
import pycurl
import certifi
from io import BytesIO
sample_string = "client ID:Client Secret"
sample_string_bytes = sample_string.encode("ascii")
base64_bytes = base64.b64encode(sample_string_bytes)
base64_string = base64_bytes.decode("ascii")
print(f"Encoded string: {base64_string}")
buffer = BytesIO()
c = pycurl.Curl()
# Autodesk documentation
#curl -v 'https://developer.api.autodesk.com/authentication/v2/token' \
# -X 'POST' \
# -H 'Content-Type: application/x-www-form-urlencoded' \
# -H 'Accept: application/json' \
# -H 'Authorization: Basic <BASE64_ENCODED_STRING_FROM_STEP_2>' \
# -d 'grant_type=client_credentials' \
# -d 'scope=data:write data:read bucket:create bucket:delete'
c.setopt(c.URL, 'https://developer.api.autodesk.com/authentication/v2/token \
-X POST \
-H Content-Type: application/x-www-form-urlencoded \
-H Accept: application/json \
-H Authorization: Basic f{base64_string} \
-d grant_type=client_credentials \
-d scope=data:write data:read bucket:create bucket:delete')
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.CAINFO, certifi.where())
c.perform()
c.close()
body = buffer.getvalue()
# Body is a byte string.
# We have to know the encoding in order to print it to a text file
# such as standard output.
print(body.decode('iso-8859-1'))
Upvotes: 0
Views: 139