无法使用 python API 发布,登录状态 - 密钥错误:"name='loggedin', domain=None, path=None"



我正试图使用这个python api包装器在minds.com上发布评论。

然而,它似乎并没有发出评论和错误:(我仍然不知道如何在这里发布stacktraces,但我在这里有它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)]>

这是导致错误的代码:
/meds/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

/头脑/部分/职位.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已经消失,您将不会在cookie中再次看到此参数,您必须将其更改为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

最新更新