请求“处理程序应为loggedin时无上下文”

2024-04-20 10:15:42 发布

您现在位置:Python中文网/ 问答频道 /正文

上下文:

我正在尝试编写自己的货币聚合器,因为市场上大多数可用的工具还没有覆盖所有的金融网站。我正在raspberrypi上使用python 2.7.9

到目前为止,由于请求或Dryscrap库,我成功地连接到了我的一些帐户。我现在试图聚合的网站给我带来了困难(比我发布的网站更困难),它的名字是https://www.linxo.com(实际上它本身就是一个聚合器)

这次我决定使用请求(我不确定这可能是个错误的选择)

问题

通过模拟来自浏览器的curl请求来运行此代码时

import requests

with requests.Session() as s:
    headers = {
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'en-US,en;q=0.8,fr;q=0.6',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/59.0.3071.109 Chrome/59.0.3071.109 Safari/537.36',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
        'Referer': 'https://wwws.linxo.com/auth.page',
        'Connection': 'keep-alive',
    }

    r_init = s.get('https://wwws.linxo.com/auth.page#Login', headers=headers)

    linxoSession = r_init.cookies.items()[1][1]  

    r_connect = s.get('https://wwws.linxo.com/secured/overview.page', headers=headers) 

    headers = {
        'Origin': 'https://wwws.linxo.com',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'en-US,en;q=0.8,fr;q=0.6',
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/59.0.3071.109 Chrome/59.0.3071.109 Safari/537.36',
        'Content-Type': 'text/x-gwt-rpc; charset=UTF-8',
        'Accept': '*/*',
        'X-GWT-Module-Base': 'https://wwws.linxo.com/secured/js/',
        'X-GWT-Permutation': 'DB8126A36E6BF1903AACA5D5D293D391',
        'Referer': 'https://wwws.linxo.com/secured/overview.page',
        'Connection': 'keep-alive',
    }

    data = '7|0|7|https://wwws.linxo.com/secured/js/|XXXXXXXX|net.customware.gwt.dispatch.client.standard.StandardDispatchService|execute|net.customware.gwt.dispatch.shared.Action|com.linxo.gwt.rpc.client.auth.CheckSessionAction/4080764126|' + linxoSession + '|1|2|3|4|1|5|6|7|'
    r_connect = s.post('https://wwws.linxo.com/secured/js/dispatch', headers=headers, cookies=r_connect.cookies, data=data)

最后一个请求的结果是

 //EX[2,0,0,1,["com.linxo.gwt.rpc.client.exception.InvalidSessionException/3836580376","No context while handler is supposed to be logged-in"],0,7]

问题:

  • 为什么我会有这样的错误消息?我如何才能登录到
    网站是否正确检索我正在查找的数据
  • 我是否应该使用另一个库,如dryscrap

Tags: httpscomauth网站connectpagerpcen
1条回答
网友
1楼 · 发布于 2024-04-20 10:15:42

最后,我在raspberry pi和Firefox上使用selenium进行调试,在PhantomJS上运行程序headless。 它大大加快了我的编码时间,但性能可能会更低,我并不介意

相关问题 更多 >