python - 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()
解决方案
推荐阅读
- typescript - 如何将 TypeScript 用于 next.js 服务器?
- java - 为什么这个方法总是返回 -1
- python - 与多处理一起使用时,PyTesseract 调用工作非常缓慢
- python - Pandas DataFrame 中列表中元素的位置
- javascript - 如何在数据更改时呈现动态数组并更新
- javascript - 将两个数字与字符串相加
- java - bonigarcia webdrivermanager firefox浏览器问题
- ruby - 为什么有这么多断言?简单的“断言”还不够吗?
- javascript - 通过 ES6 中的 Express 和使用 OOP 概念(类等)构建 Node js 项目
- php - Foreach 的 Selenium WebDrive 问题