gpt4 book ai didi

python - 无法使用 python api 发布,登录状态 - KeyError : "name=' loggedin', 域=无,路径=无”

转载 作者:太空宇宙 更新时间:2023-11-03 21:27:39 26 4
gpt4 key购买 nike

我正在尝试使用 this python api-wrapper在 Minds.com 上发表评论。

但是,它似乎没有发送评论和错误:(我仍然不知道如何在这里发布堆栈跟踪,但我在这里有它 https://paste.pound-python.org/show/pV9iHbAyBB1mxfw2zoGD/ )。

我确信我似乎已登录,因为在运行 minds_api.con.cookies 时,它确实在登录后的 json 响应中显示了我的用户凭据。这就是通过 API 登录时 cookie 的样子(为了确保安全,我确实修改了一些值):

<RequestsCookieJar[Cookie(version=0, name='socket_jwt', value='eyJ0eXAiOiJKV1QiLCJhbGdiOiJIUzI1NiJ9.eyJndWlkIjoiNjE4NDUZu4g5NDgwMjA1IiwiZXhwaXJlcyI6MUIQLEU5NCwic2VlKDiVuDVmNTUzYmY3OTEyMzk2YTQyMGE5ZTkxMWI3NTlhMjNkZmQ0MzA2ZGRiNzI1MjgwZjgzODk5MTlhMzlkOGQ2ZTVjN2M0ZWFlZThjYjExZjFiYNkzUPZWVmYTYxNDZiOWI5MGNlMzQ2YTJiM2FkNhafdNDAzMjk5NGVmOTAzYzMifQ.iEkw_KnxCuB9AXh2nrYKjtT9tfOT8PDsit-bgAG7pVQ', port=None, port_specified=False, domain='.minds.com', domain_specified=True, domain_initial_dot=False, path='/', path_specified=True, secure=True, expires=1544640594, discard=False, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False), Cookie(version=0, name='XSRF-TOKEN', value='6ebd8e04de96p55df0ee5939a6db6562dd358b1420ef4eb34dhfgg311d7596f45f5371d34588937cb38e5652f6df783a9f74f69da5b263c4b66fba6', port=None, port_specified=False, domain='www.minds.com', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=True, expires=None, discard=True, comment=None, comment_url=None, rest={}, rfc2109=False), Cookie(version=0, name='minds_sess', value='eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzUxMiIsImp0aSI7IKPhtBnRqJmNzkxMjM5NmE0MjBhOWU5MTFiNzU5YTIzZGZkNDMwNmRkYjcyNTI4MGY4Mzg5OTE5YTM5ZDhkNmU1YzdjNGVhZWU4Y2IxMWYxYmM3YTI2YWVlZmE2MTQ2YjliOTBjZTM0NmEyYjNhYjQ4MDQwMzI5OTRlZjkwM2MzIn0.eyJqdGkiOiI4NWY1NTNiZjc5MTIzOTZhNDIwYTllOTExYjc1OWEyM2RmZDQzMDZkZGI3MjUyODBmODM4OTkxOWEzOWQ4ZDZlNWM3YzRlYWVlOGNiMTFmMWJjN2EyNmFlZWZhNjE0NmI5YjkwY2UzNDZhMmIzYWI0ODA0MDMyOTk0ZWY5MDNjMyIsImV4cCI6MTU0NzIyODk5NCwidXNlcl9ndWlkIjoiNjE4NDU3NDI5Mjg5NDgwMjA1In0.l1KMPobfarC00mLdxyUKmqHenRMkyepvB0VEAUjPwqm7kzFXtskTzMNkxEH3dTfZ0_p_Oqlx4sYq5FfDe_1Wwi3V2ZZoiUbdpAyw6qmZnEozmkWBHuMKT0ZishnUEa5HPn9keMjdAxKFfyGVjbU7AQ0QFt4pcluzXbSauwlhOtvS28FWz7pzyrNUgiuVoBRWPwfVUQwnryBJLGxYNrDd3wlFxCujG8E4ynlCHgAWzVTuFzy5YT2UhsbCOQgAK2Pd3RGumezPg3njSvNN968H1Od2vYCCmcx7xnEnjVJjgG-JY9zkULmge54D5Va_Ne5tJlxHznH1DKVmf0ThSHGnM3g', port=None, port_specified=False, domain='www.minds.com', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=True, expires=1547228994, discard=False, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)]>

这是导致错误的代码:
/minds/utils.py

from functools import wraps
from urllib.parse import quote, urlparse

from minds.exceptions import AuthenticationError

(...)
def requires_auth(func):
"""Decorator for that checks whether loggedin cookie is present in the current session"""

@wraps(func)
def new_func(self, *args, **kwargs):
if not self.con.cookies['loggedin'] == '1':
raise AuthenticationError(
f'{type(self).__name__}.{func.__name__} requires authentication, call "authenticate" method first or provide username password kwars upon object creation')
return func(self, *args, **kwargs)

return new_func

/minds/sections/posting.py

from minds.utils import requires_auth
from minds.endpoints import *


class PostingAPI:
def _post_comment(self, guid, message, wire_treshold=None, is_rich=0, title='', description='',
thumbnail='', url='', attachment_guid=None, mature=0, access_id=2) -> dict:
body = {k: v for k, v in locals().items() if k != 'self'}
resp = self.con.post(COMMENT_URLF(guid), json=body)
return resp.json()

(...)

@requires_auth
def post_newsfeed(self, message, attached_url='', mature=False, **kwargs) -> dict:
"""Post something to user's newsfeed.

:param message: text message of post content
:param attached_url: urls that should be attached to the post
:param mature: whether post should be marked mature or not

.. note:: requires auth
"""
return self._post_newsfeed(message=message, url=attached_url, mature=int(mature), **kwargs)

有办法解决发帖错误吗?

最佳答案

好的,这是你的第二个问题:)。网站发生了很大变化,所以这个库已经过时了。 loggedin 消失了,你在 cookies 中将看不到这个参数,你必须将其更改为 if not self.con.cookies.get("minds_sess")

def requires_auth(func):
"""Decorator for that checks whether loggedin cookie is present in the current session"""

@wraps(func)
def new_func(self, *args, **kwargs):
if not self.con.cookies.get("minds_sess"):
raise AuthenticationError(
f'{type(self).__name__}.{func.__name__} requires authentication, call "authenticate" method first or provide username password kwars upon object creation')
return func(self, *args, **kwargs)

return new_func

关于python - 无法使用 python api 发布,登录状态 - KeyError : "name=' loggedin', 域=无,路径=无”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53748894/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com