首页 > 解决方案 > pywhatkit 库出现 502 错误网关错误

问题描述

我正在尝试使用 pywhatkit 向 WhatsApp 发送消息。使用 Flask 框架。在本地,它运行良好,但是当我在谷歌云上部署代码时,它给了我一个 502 bad gateway 错误。我启用了 google sheet API 和 cloud build API。我无法识别我的错误。

from flask import Flask,request,render_template
import pywhatkit
import pickle
from googleapiclient.discovery import build
from google.oauth2 import service_account
import itertools  
import time

app = Flask(__name__)

@app.route('/')
def hello_world():
    return render_template("test.html")

@app.route('/calling',methods=['POST','GET'])
def contact():
    if request.method == 'POST':

        if request.form['submit_button'] == 'send message to numbers from 1 to 10,000':

            SERVICE_ACCOUNT_FILE = '**********.json'

            SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
            creds = None
            creds = service_account.Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES)
            # The ID and range of a sample spreadsheet.
            SAMPLE_SPREADSHEET_ID = '*************'
            service = build('sheets', 'v4', credentials=creds)
            sheet = service.spreadsheets()


            result1 = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,range="whatsaap!A2:A100").execute()
            hour= result1.get('values')
            hour = list(itertools.chain(*hour))
         

            result2 = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,range="whatsaap!B2:B100").execute()
            minute= result2.get('values')
            minute = list(itertools.chain(*minute))
          

            result3 = sheet.values().get(spreadsheetId=SAMPLE_SPREADSHEET_ID,range="whatsaap!C2:C100").execute()
            number= result3.get('values')
            number = list(itertools.chain(*number))
     


            for i,j, k in zip(number,hour, minute):

                j= int(j)
                k= int(k)
                print(f'Output:\n{i}\n{j}\n{k}')
                pywhatkit.sendwhatmsg(i, 'hello dear, Auto whatsaap message testing', j ,k)
                time.sleep(35)

            return 'Done with messanging to numbers from 1 to 10,000' 

                
if __name__ == '__main__':
    app.run()

收到此错误: 错误

日志: 日志

日志

本地运行: 本地运行

标签: pythonnginxflaskgoogle-app-engine

解决方案


推荐阅读