Discussions
Hi i am running this code everyti me its generating its giving me an error for no reason , could you please tell me issue
import os
import uuid
import requests
import json
url = "https://auth.leialoft.com/auth/realms/leialoft/protocol/openid-connect/token"
payload = {
"grant_type": "client_credentials",
"client_id": "",
"client_secret": ""
}
headers = {
"accept": "application/json",
"content-type": "application/x-www-form-urlencoded"
}
response = requests.post(url, data=payload, headers=headers)
Parse the response JSON
response_json = response.json()
Extract the access token
access_token = response_json.get('access_token', 'Token not found')
print(access_token)
correlation_id = str(uuid.uuid4())
print(f'\nGenerating Disparity with correlationId: {correlation_id}')
MEDIACLOUD_REST_API_BASE_URL = 'https://api.leiapix.com'
ORIGINAL_IMAGE_URL = os.getenv('ORIGINAL_IMAGE_URL', 'https://images.pexels.com/photos/38771/pexels-photo-38771.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1')
THREE_MIN_IN_MS = 3 60 _ 1000 # Timeout for HTTP requests
def main():
try:
print(f"\nLeiaLogin AccessToken acquired: {access_token}")
correlation_id = str(uuid.uuid4())
print(f"\nGenerating Disparity with correlationId: {correlation_id}")
headers = {
'Authorization': f'Bearer {access_token}'
}
payload = {
'correlationId': correlation_id,
'inputImageUrl': ORIGINAL_IMAGE_URL
}
response = requests.post(f"{MEDIA_CLOUD_REST_API_BASE_URL}/api/v1/disparity",
json=payload,
headers=headers,
timeout=THREE_MIN_IN_MS / 1000) # Timeout needs to be in seconds
# Check response status and handle potential issues
response.raise_for_status()
# Assuming the response is JSON and it includes a 'resultPresignedUrl'
get_disparity_presigned_url = response.json().get('resultPresignedUrl')
print(f'\nDisparity has been uploaded to the temporary storage. To view it, use this GET URL: {get_disparity_presigned_url}')
except requests.exceptions.RequestException as e:
print(f"Error. Unhandled exception: {e}")
if name == 'main':
main()
import requests
url_2 = "https://api.leiapix.com/api/v1/animation"
payload = {
"inputImageUrl": ORIGINAL_IMAGE_URL,
"correlationId": correlation_id,
"inputDisparityUrl": 'https://leia-storage-service-production.s3.us-east-1.amazonaws.com/timed/D001/1215623e-a16e-4b51-9d53-051efbc555ea/e5e3d5a3-a35d-4c2f-9f9e-5324f5f402ec/3ff2ab61-c67a-4616-a68c-c2292d62663b/9eb2c5f6-eedc-4d73-a182-33d3ec282fb8.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIASC7ECGJVHARKLZ6E%2F20240426%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240426T144007Z&X-Amz-Expires=86400&X-Amz-Signature=fbb91febf2db1d9bb84a4b76b21e965ab0f0c5b5a24ae4dda1067740e2acc037&X-Amz-SignedHeaders=host&x-id=GetObject' ,
"animationType": "mp4",
"pattern": "0.0",
"animationLength": 3,
"outputWidth": 500,
"outputHeight": 450,
"amplitudeX": 2,
"amplitudeY": 2,
"amplitudeZ": 2,
"phaseX": 3,
"phaseY": 3,
"phaseZ": 3,
"gain": 3,
"convergence": 1,
"numberOfLoops": 3
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": "Bearer {access_token}"}
response = requests.post(url_2, json=payload, headers=headers)
print(response.text)
Output I am getting after running this is
eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJhMWZUdW1mb1RXbGJENUtEN1ZLbF8xZmluREg0ZTBQTG9NOWMwQTl4WFpjIn0.eyJleHAiOjE3MTQxNDM0MzAsImlhdCI6MTcxNDE0MjUzMCwianRpIjoiNjVjZDYwMWYtMjc4Zi00ZjdjLTk4MzYtMTg1ZTRkYzhmNjdmIiwiaXNzIjoiaHR0cHM6Ly9hdXRoLmxlaWFsb2Z0LmNvbS9hdXRoL3JlYWxtcy9sZWlhbG9mdCIsInN1YiI6IjQ4MmMyODdjLTBiYjgtNDcyYi04NzZkLWM5ZjMxMDM0YTg1MCIsInR5cCI6IkJlYXJlciIsImF6cCI6IjIwNTY0YjlkLWFlZGItNDlkYy1iMTM2LTNjOWIxNTI2ZjMwYSIsImFjciI6IjEiLCJzY29w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kYy1iMTM2LTNjOWIxNTI2ZjMwYSIsImFjciI6IjEiLCJzY29wZSI6ImxlaWEtYXBpLWdhdGV3YXkiLCJjbGllbnRJZCI6IjIwNTY0YjlkLWFlZGItNDlkYy1iMTM2LTNjOWIxNTI2ZjMwYSIsImNsaWVudC1vd25lci11c2VyLWlkIjoiMTIxNTYyM2UtYTE2ZS00YjUxLTlkNTMtMDUxZWZiYzU1NWVhIiwiY2xpZW50SG9zdCI6IjQ3LjkuMTQ2LjEzNyIsImNsaWVudEFkZHJlc3MiOiI0Ny45LjE0Ni4xMzcifQ.GAndbLsuTGO890eHTNjU8sFXVIg-XgFCr7IGwFs1EG8fcMl068gFPDD5cZh1wx3vtnr-xVroIvEqY7dwfqH9XaioApGi3U-XhAeWtqzSORvMxbxUIme7mBjDtBkeah7-JSVy_pGF1UyZw6WYV-QptJ3uV7K2xyPV0yD9oxvsT4B_VI8_MwjbDb07vi1AdBkVsbFHTB1VzLyZRrpW9Qlv8MJFz6P9EHtgfj2Q15u3MKat16KWT2ZU3fWifQ6caxyiuGARS9icwi5q3fxnp3n56jj-N0qafnKauGaF8_sz1FUiG0nB_X8aM6a2k7FUrVOyGz1YTwF0Vup1O83vatxxVA
Generating Disparity with correlationId: 6b3688f8-4c16-4a06-b76e-64c2c890eaff
Disparity has been uploaded to the temporary storage. To view it, use this GET URL: https://leia-storage-service-production.s3.us-east-1.amazonaws.com/timed/D001/1215623e-a16e-4b51-9d53-051efbc555ea/e5e3d5a3-a35d-4c2f-9f9e-5324f5f402ec/9ba63a62-2f33-4293-bbd6-1e11ef968a38/d9e3d1cd-ff2a-45ac-9c16-8311226c29e7.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIASC7ECGJVHARKLZ6E%2F20240426%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240426T144213Z&X-Amz-Expires=86400&X-Amz-Signature=2867749af14fcc6e85b3b08b0dffea39107a5a99f7d61ecf23ef25f669ff4a0e&X-Amz-SignedHeaders=host&x-id=GetObject
{"statusCode":401,"message":"Unauthorized"} So why I am not able to genearate image after getting access token and every thing else .