Answer the question
In order to leave comments, you need to log in
How to send such a complex request to the smartcat site?
Hello.
I can't figure out how to send a multiplay request to the smartcat site .
I need to create a project on their site, this is the documentation I have .
Constantly returning error 500,
Here is my code:
import requests
import base64
import json
def run():
account_id = 'f802238b-58****ab51-2989606f4745'
key = '3_0KgI4JvUDQNLcluZYnzA4YCad'
base_url = 'https://smartcat.ai/'
key = account_id+ ':' + key
projectID = "d5925bdb-******-969a-a70ef6bc703a"
# project = base64.b64encode(bytes(project,"utf-8"))
encoded_key = base64.b64encode(bytes(key, 'utf-8'))
with open("project.json","r") as f:
project = f.read()
project = base64.b64encode(bytes(project,"utf-8"))
headers = {
"Authorization" : "Basic "+encoded_key.decode(),
"project" : project.decode()
}
response = requests.post(base_url+'/api/integration/v1/project/create', headers=headers)
print(response)
run()
Answer the question
In order to leave comments, you need to log in
You overdid something. There is no need to encode anything. Requests will do everything by itself. For example,
files = {'file1': open('some_project_file1.txt', 'rb'), 'file2': open('some_project_file2.txt', 'rb')}
response = requests.post(base_url+'/api/integration/v1/project/create', data=project_json, files=files)
You know, I always thought that a person with such programming experience should read and understand texts in English without any problems.
import requests
from requests.auth import HTTPBasicAuth
import base64
import json
def run():
account_id = 'f802238b-58****ab51-2989606f4745'
key = base64.b64encode(bytes('3_0KgI4JvUDQNLcluZYnzA4YCad'))
auth = HTTPBasicAuth(account_id, key)
url = 'https://smartcat.ai/api/integration/v1/project/create'
with open("project.json","r") as f:
project = json.load(f)
headers = {'Content-Type': 'application/json'}
response = requests.post(url, data=project, headers=headers, auth=auth)
print(response)
run()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question