Posts tagged with flask

I'm pretty new to python and Flask development. I'm primarily a frontend JavaScript/React developer.

I am building a tool that uses the Google Ads api, and their documentation had me create a yaml file with my refresh tokens and other important info.

I'm trying to deploy my flask app to render.com and I'm unsure what to do with the yaml files since I want to keep my tokens secure. Any advice?

So far I've tried adding my tokens in an env file and reading them that way, but it looks like the google ads api needs the yaml file.

Hello fellow developers,

I hope you're all doing well. I am currently setting up a bot (LLM agent) using WhatsApp API and a Flask application hosted on Azure.

As recommended in Azure's tutorial, I have a startup.txt with the following command

gunicorn --bind=0.0.0.0 --timeout 600 --chdir src/whatsapp_agent/whatsapp_agent run:app

which runs locally without an issue.

Once it is deployed on Azure, however, the webhook setting from WhatsApp API (Edit Whatsapp Business Account subscription) returns the following error:

The URL couldn't be validated. Callback verification failed with the following errors: curl_errno = 28; curl_error = Operation timed out after 6000 milliseconds with 0 bytes received; HTTP Status Code = 200; HTTP Message = Connection established

Did anyone run into a similar issue and managed to solve it?

Many thanks!

I have been using a Twilio phone number connected to a WhatsApp Business Account.

As far as I understand, for each conversation started, WhatsApp gives me a 24-hour window where I can send and receive any number of messages without additional charges (WhatsApp Conversation - Free Tier). However, it seems that I am somehow incurring in additional charges for each message sent and received (Messaging Channels Inbound Message and Messaging Channels Outbound Message where each costs $0.005).

I configured the WhatsApp sender to work with a webhook redirecting to an Azure Function App running Python Flask. Despite I can answer an incoming message via a Python Flask, I chose answering via the Twilio REST API (from twilio.rest import Client), since the webhook method gives me only 15 seconds to send an answer or it cuts the connection throwing error 11200, and some of my processes take longer than that.

Are this extra costs because I am using the Twilio REST API or is this a normal behavior of Twilio WhatsApp?

We are building a chatbot for WhatsApp using the OpenAI API, which is intended to be able to answer any question asked to it. However, we are experiencing some issues when trying to integrate the OpenAI API with the WhatsApp Business API. Here is the code we are using for this integration:

import os import requests from flask import Flask, request import openai from Testbotgpt import generate_response app = Flask(__name__) def send_message(to, text):     data = {         "recipient_type": "individual",     "to": "whatsapp:{}".format(to),     "type": "text",     "text": {       "body": text     }     }     headers = {         'Content-Type': 'application/json',         'Authorization': 'Bearer <Access Token>'     }     api_url = 'https://api.whatsapp.com/v1/messages'     response = requests.post(api_url, json=data, headers=headers)     if response.status_code != 200:                raise ValueError('Error sending message: {}'.format(response.text)) @app.route('/bot', methods=['POST']) def bot():     incoming_msg = request.values.get('Body', '').lower()     from_number = request.values.get('From', '')     responded = False      # Check if the message contains a greeting     if 'hi' in incoming_msg:         send_message(from_number, "Hello! How can I help you today?")         responded = True     elif 'bye' in incoming_msg:         send_message(from_number, "Goodbye! Have a great day.")         responded = True        # Use the GPT model to generate a response based on the user's input     else:         response = generate_response(incoming_msg)         send_message(from_number, response)         responded = True           return 'OK' if __name__ == '__main__':   app.run() 

Could you please help us understand what we are doing wrong and suggest a solution to fix the issue?

Tried Option didn't work used in app.py

os.environ['PYTHONHTTPSVERIFY'] = '0' ssl._create_default_https_context = ssl._create_unverified_context 

using flask

data = report_downloader.DownloadReport( report, output, skip_report_header=False, skip_column_header=False, skip_report_summary=False, include_zero_impressions=True) 

and trying to get ACCOUNT_PERFORMANCE_REPORT working fine on local system when used tiangolo/uwsgi-nginx-flask:python3.6 as docker base image and deployed giving below error

 File "/google-analytics/helper_service/service.py", line 328, in sync_google_ads_word_data skip_report_summary=False, include_zero_impressions=True) File "/usr/local/lib/python3.6/site-packages/googleads/common.py", line 405, in Wrapper return utility_method(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/googleads/adwords.py", line 1268, in DownloadReport output, **kwargs) File "/usr/local/lib/python3.6/site-packages/googleads/adwords.py", line 1540, in _DownloadReport response = self._DownloadReportAsStream(post_body, **kwargs) File "/usr/local/lib/python3.6/site-packages/googleads/adwords.py", line 1614, in _DownloadReportAsStream response = self.url_opener.open(request) File "/usr/local/lib/python3.6/urllib/request.py", line 526, in open response = self._open(req, data) File "/usr/local/lib/python3.6/urllib/request.py", line 544, in _open '_open', req) File "/usr/local/lib/python3.6/urllib/request.py", line 504, in _call_chain result = func(*args) File "/usr/local/lib/python3.6/urllib/request.py", line 1361, in https_open context=self._context, check_hostname=self._check_hostname) File "/usr/local/lib/python3.6/urllib/request.py", line 1320, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)>