我正在尝试使用python-telegram
库:https ://github.com/alexander-akhmetov/python-telegram/
帮助我弄清楚如何在我的 tg.call_method 请求中将 InputChatPhoto 发送到服务器:
from telegram.client import Telegram
import base64
import json
class InputChatPhoto:
def __init__(self, name="photo.jpg"):
image = open(name, 'rb')
encoded_image = base64.b64encode(image.read())
self.photo = encoded_image.decode("ascii")
tg = Telegram(
api_id=123,
api_hash='12312',
phone='+799999999', # you can pass 'bot_token' instead
database_encryption_key='changekey123',
)
tg.login()
result = tg.get_authorization_state()
result.wait()
print("AUTH: ", result.update)
image = InputChatPhoto()
print(type(image))
result = tg.call_method(method_name="setProfilePhoto",
params={"photo":{
"@type":"inputChatPhotoStatic",
"photo_":{
"@type": "inputFileLocal",
"path_": "home/usr/photo.jpg"
}
}
})
result.wait()
print(result.update)
print(result.ok_received) # False
print(result.error_info)
# {'@type': 'error', 'code': 400, 'message': 'InputFile is not specified', '@extra':
# {'request_id': '15f855f9662f4b3c9bd22dc43ef0482b'}}
print(result.error) # True
tg.stop() # you must call stop at the end of the script
我试图发送原始字节 - 没有奏效。得到消息:'期望 TDlib 对象得到字符串'
我很想发送 inputFileRemote - 也没有用。得到同样的错误:'未指定输入文件'
我应该如何指定?在文档类 inputFileLocal 中仅包含path_
字段。inputFileRemote 包含id_
我指定的内容,但仍然没有好处:(