1

I'm trying to use this python api-wrapper to post a comment on minds.com .

Howerver, it doesn't seem to send the comment and errors out: (I still don't know how to post stacktraces on here, but I have it here instead https://paste.pound-python.org/show/pV9iHbAyBB1mxfw2zoGD/).

I am sure that I seem to be logged in because it does show my user credentials at the json-response after login when running minds_api.con.cookies. And this is how cookies look like when logged in via the API (I did modify some values just to be shure):

<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)]>

This is the code responsible for the error:
/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)

Is there a way to resolve the error to post?

1
  • What happens if you first request a feed or do some other "get request" action and only then post a comment?
    – alecxe
    Dec 12, 2018 at 18:13

1 Answer 1

0

Ok, this is your second issue :). The website has changed a lot, so this library is outdated. loggedin is gone that you will not see this parameter again in cookies , and you have to change it into 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
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.