【发布时间】:2021-07-13 00:47:56
【问题描述】:
我是 python 新手,我想用Telethon 设置一个谷歌云功能,但我不能这样做,因为我在运行时出错。
这是我的Gcloud功能代码:
from telethon import TelegramClient, events, sync
#from telethon import functions, types
#from telethon.tl.functions.channels import CreateChannelRequest, CheckUsernameRequest, UpdateUsernameRequest, InviteToChannelRequest
#from telethon.tl.types import InputChannel, InputPeerChannel
api_id = XXX
api_hash = 'XXX'
def hello_world(request):
with TelegramClient("session_name", api_id, api_hash) as client:
from telethon.tl.functions.channels import CreateChannelRequest, CheckUsernameRequest, UpdateUsernameRequest
from telethon.tl.types import InputChannel, InputPeerChannel
from telethon.tl.types import InputPhoneContact
from telethon.tl.types import InputPeerUser
from telethon.tl.functions.contacts import ImportContactsRequest
contact = InputPhoneContact(client_id=11111, phone='1111111111', first_name="Twilo Test",last_name="Phone")
newcontact = client(ImportContactsRequest(contacts=[contact]))
return newcontact.__dict__;
我的 requeriments.txt:
# Function dependencies, for example:
# package>=version
telethon
当我运行函数 (hello_world) 时出现以下错误:
【问题讨论】:
-
我已尝试重现此问题,但没有收到任何错误。如果您查看错误,它会显示 sqlite3.DatabaseError,但您没有提及数据库以及如何使用它,请编辑您的问题以在代码中显示数据库的使用情况。
-
嗨@ZeenathSN 感谢您的回答。这是我在 Google Cloud Function 中的所有代码。你用了谷歌云功能吗?也许 Telethon 使用数据库!在我本地的情况下,代码运行良好。
-
是的,我在云功能中做到了。您能否参考此文档再次尝试创建函数:cloud.google.com/functions/docs/first-python 并告诉我们您在哪一步收到此错误?
标签: python google-cloud-functions telegram telethon