Posts tagged with python-3.x

I've read the docs and try to make a function to upload image on facebook and get its api but it seems not work at all. (the access token have permisson to do that request so ye)

def upload_image(token, gid, image_path):         res = requests.post(f"https://graph.facebook.com/{gid}/photos", params={"access_token": token}, files={"source": open(image_path, "rb")})         print(res.text)         return res.json().get("id") 

The weird part is I kept getting the error #324 (Requires upload file).

I'm using the Google Ads API to retrieve information from Google Ads campaigns. Initially, I manually generated a new refresh token by following specific steps to obtain an authorization code using a designated Google ID. Subsequently, I sent a CURL request with that code to generate a refresh token. Now, I aim to automate the entire process to convert the script, responsible for fetching Google Ads campaign data, into a full-time scheduler by automating the generation and renewal of the refresh token. Unfortunately, I'm encountering difficulties in achieving this. Is there a specific code or method available to accomplish the aforementioned task?

I would like to obtain the process and code for the aforementioned issue.

Can anyone help make sense of this?

Using google python sdk as an example, according to Google retry policy (https://cloud.google.com/python/docs/reference/storage/latest/retry_timeout):

from google.api_core import exceptions from google.api_core.retry import Retry _MY_RETRIABLE_TYPES = (    exceptions.TooManyRequests,  # 429    exceptions.InternalServerError,  # 500    exceptions.BadGateway,  # 502    exceptions.ServiceUnavailable,  # 503 ) def is_retryable(exc):     return isinstance(exc, _MY_RETRIABLE_TYPES) my_retry_policy = Retry(predicate=is_retryable) 

Why does the following occur when testing is_retryable?

exceptions.TooManyRequests==exceptions.TooManyRequests -> True is_retryable(exceptions.TooManyRequests) -> False  is_retryable(429) -> False  is_retryable(exceptions.TooManyRequests.code) -> False is_retryable(exceptions.TooManyRequests.code.value) -> False  

I want to get keywords' historical metrics using google Ads API, but I must create a keyword plan and get the data, but it also has other keyword suggestions which is not needed. Currently am using keyword idea endpoint in which the given keyword is the first row with data. How to use the historical metrics endpoint without creating a keyword plan?

https://developers.google.com/google-ads/api/docs/keyword-planning/generate-historical-metrics

When doing an api call, I'm getting the response 400 with reason

"Unsupported post request. Object with ID '###############' does not exist, cannot be loaded due to missing permissions, or does not support this operation".

Though the permissions for whatsapp_business_messaging and whatsapp_business_management was given and token was generated for an admin user.

Is it that permanent tokens does not work on apps with apps in development mode? Because the temporary token was working with the same code and messages were being sent correctly.

I'm trying this for Odoo 16 in python 3.8 `

recipient_phone_number = rec.owner_id.partner_id.mobile url = f"https://graph.facebook.com/v15.0/{phone_number_id}/messages" headers = {     "Authorization": f"Bearer {access_token}",     'Content-Type': 'application/json' } # Code for sending text message in whatsapp. text_data = {     'messaging_product': 'whatsapp',     "recipient_type": "individual",     'to': recipient_phone_number,     'type': 'text',     "text": {         "preview_url": False,         "body": "Dear %s, this message is to remind that document %s will expire on %s."                 % (rec.owner_id.name, rec.name, rec.expiry_date)     } } text_response = requests.post(     url,     headers=headers,     data=json.dumps(text_data) ) 

`