无法使用python minds api进行身份验证 - python

我试图通过this python api访问本地社交网站minds.com,方法是使用python3 setup.py install && pipenv run python在本地安装该模块并按照说明进行登录。

但是,尝试进行身份验证时,我收到此错误消息:

(由于某种原因,Stackoverflow不允许我发布python错误日志,因为它没有正确缩进,因此这里是https://pastebin.com/0sWa1hmY)

该代码似乎是从python api调用的,如下所示:

minds/api.py

# -*- coding: utf-8 -*-
from pprint import pprint

from requests.utils import dict_from_cookiejar, cookiejar_from_dict

from minds.connections import XSRFSession
from minds.exceptions import AuthenticationError
from minds.profile import Profile
from minds.utils import add_url_kwargs
from minds.endpoints import *
from minds.sections import NewsfeedAPI, ChannelAPI, NotificationsAPI, 
PostingAPI, InteractAPI


class Minds(NewsfeedAPI, ChannelAPI, NotificationsAPI, PostingAPI, ...):
    _xsrf_retries = 5

    def __init__(self, profile: Profile = None, login=True):
        self.con = XSRFSession()
        self.profile = profile
        if self.profile:
            if profile.cookie:
                self.con.cookies = cookiejar_from_dict(profile.cookie)
            if profile.proxy:
                self.con.proxies = {'https': profile.proxy, 'http':\
                profile.proxy}
        self._establish_xsrf()
        if self.profile and login and not self.is_authenticated:
            if profile.username and profile.password:
                self.authenticate(profile.username, profile.password)

(...)

def authenticate(self, username, password, save_profile=True) -> dict:
    """
    Authenticate current instance with given user
    :param: save_profile: whether to save profile locally
    """
    auth = {
        'username': username,
        'password': password
    }
    resp = self.con.post(AUTHENTICATE_URL, json=auth)
    self.user = resp.json()
    if self.user['status'] == 'failed':
        raise AuthenticationError("Couldn't log in with the ...")
    self.guid = self.user['user']['guid']
    if save_profile:
        Profile(
            username=username,
            password=password,
            cookie=self.get_cookies(),
            proxy=self.con.proxies.get('https'),
        ).save()
    return resp.json()

似乎未维护python API,但我认为minds.com新使用jsonwebtokens进行身份验证。 api中缺少的东西要启用jwt吗?

参考方案

与浏览器比较后一次又一次地请求。发生错误的原因是您给了错误的内容类型,但是实际上您需要作为json数据发送(似乎网站在开玩笑)。因此,您需要指定headers["content-type"] = "text/plain"。否则,网站将回复500。

注意:为避免广泛讨论,我只能回答此错误。

将代码更改为以下代码,但与源代码只有一行不同:)。

def authenticate(self, username, password, save_profile=True) -> dict:
    """
    Authenticate current instance with given user
    :param: save_profile: whether to save profile locally
    """
    auth = {
        'username': username,
        'password': password
    }
    self.con.headers["content-type"] = "text/plain" ####
    resp = self.con.post(AUTHENTICATE_URL, json=auth)
    self.user = resp.json()
    if self.user['status'] == 'failed':
        raise AuthenticationError("Couldn't log in with the given credentials")
    self.guid = self.user['user']['guid']
    if save_profile:
        Profile(
            username=username,
            password=password,
            cookie=self.get_cookies(),
            proxy=self.con.proxies.get('https'),
        ).save()
    return resp.json()

R'relaimpo'软件包的Python端口 - python

我需要计算Lindeman-Merenda-Gold(LMG)分数,以进行回归分析。我发现R语言的relaimpo包下有该文件。不幸的是,我对R没有任何经验。我检查了互联网,但找不到。这个程序包有python端口吗?如果不存在,是否可以通过python使用该包? python参考方案 最近,我遇到了pingouin库。

如何用'-'解析字符串到节点js本地脚本? - python

我正在使用本地节点js脚本来处理字符串。我陷入了将'-'字符串解析为本地节点js脚本的问题。render.js:#! /usr/bin/env -S node -r esm let argv = require('yargs') .usage('$0 [string]') .argv; console.log(argv…

将字符串分配给numpy.zeros数组[重复] - python

This question already has answers here: Weird behaviour initializing a numpy array of string data                                                                    (4个答案)         …

Python:传递记录器是个好主意吗? - python

我的Web服务器的API日志如下:started started succeeded failed 那是同时收到的两个请求。很难说哪一个成功或失败。为了彼此分离请求,我为每个请求创建了一个随机数,并将其用作记录器的名称logger = logging.getLogger(random_number) 日志变成[111] started [222] start…

Python-Excel导出 - python

我有以下代码:import pandas as pd import requests from bs4 import BeautifulSoup res = requests.get("https://www.bankier.pl/gielda/notowania/akcje") soup = BeautifulSoup(res.cont…