我正在编写一个小型机器人,可以在Mastodon时间轴上发布随机图像。该机器人是使用versoin 1.4.0中的Mastodon.py模块在Python 3中编程的(但v 1.3.1不能正常工作)
为了使公共时间表井井有条,我在家里的虚拟机上设置了一个私人Mastodon实例。
但是,由于无法从Internet到达该实例,因此我无法让该实例的证书加密。
默认情况下,Mastodon.py模块无法使用没有适当证书的实例。
此外,该类构造可以允许使用自定义的Session对象,因此我正在尝试运行以下代码:
uc_client_id = get_parameter("client_id", secrets_filepath)
uc_client_secret = get_parameter("client_secret", secrets_filepath)
uc_access_token = get_parameter("access_token", secrets_filepath)
mastodon_hostname = get_parameter("mastodon_hostname", secrets_filepath)
verify_ssl = get_parameter('verify_ssl', secrets_filepath)
s = requests.Session()
s.verify = verify_ssl
mastodon = Mastodon(
session = s,
client_id = uc_client_id,
client_secret = uc_client_secret,
access_token = uc_access_token,
api_base_url = 'https://' + mastodon_hostname,
)
(当然,我是在脚本顶部导入所需的模块)
但是当我尝试运行bot时,出现以下错误消息:
oupsman@CHIOT:/mnt/c/Users/benoi/PycharmProjects/untitled$ python3 nsfw-bot.py
Traceback (most recent call last):
File "nsfw-bot.py", line 274, in <module>
api_base_url = 'https://' + mastodon_hostname,
TypeError: __init__() got an unexpected keyword argument 'session'
奇怪的是,根据文档https://mastodonpy.readthedocs.io/en/stable/
,会话是构造函数的允许关键字我被困在这里,无法弄清楚为什么我的代码没有运行。
有人可以帮我吗?