1

对,你好,所以我正在尝试使用 trio 和询问( https://asks.readthedocs.io/ )用我的 web 应用程序实现 opticard(忠诚卡服务)。

所以我想向他们的查询 api 发送一个请求:这里使用请求:

import requests
r = requests.post("https://merchant.opticard.com/public/do_inquiry.asp", data={'company_id':'Dt', 'FirstCardNum1':'foo', 'g-recaptcha-response':'foo','submit1':'Submit'})

这将返回“Invalid ReCaptcha”,这是正常的,也是我想要的

使用 aiohttp 也是一样的:

import asyncio
import aiohttp

async def fetch(session, url):
    async with session.post(url, data={'company_id':'Dt', 'FirstCardNum1':'foo', 'g-recaptcha-response':'foo','submit1':'Submit'} ) as response:
        return await response.text()

async def main():
    async with aiohttp.ClientSession() as session:
        html = await fetch(session, 'https://merchant.opticard.com/public/do_inquiry.asp')
        print(html)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

现在这也返回“无效的 ReCaptcha”,所以这一切都很好。

但是现在,使用三重奏/询问:

import asks
import trio

async def example():
    r = await asks.post('https://merchant.opticard.com/public/do_inquiry.asp', data={'company_id':'Dt', 'FirstCardNum1':'foo', 'g-recaptcha-response':'foo','submit1':'Submit'})
    print(r.text)
trio.run(example)

这将返回一个完全不同的响应,“您的会话已过期以保护您的帐户。请重新登录。',当输入一个无效的url例如' https://merchant.opticard.com/do_inquiry.asp '而不是' https://merchant.opticard.com/public时可以正常访问此错误/消息/do_inquiry.asp '。

我不知道这个错误是从哪里来的,我尝试设置标头、cookie、编码,但似乎没有任何效果。我尝试复制该问题,但我设法使用 aiohttp 和 requests 复制结果的唯一方法是设置一个不正确的 URL,例如“ https://merchant.opticard.com/do_inquiry.asp ”而不是“ https://merchant .opticard.com/public/do_inquiry.asp '。

这一定是询问的问题,可能是由于编码或格式化,但我已经使用询问一年多了,并且从未遇到过与其他任何地方相比,带有数据的简单发布请求在询问上的返回不同的问题。而且我很困惑,因为我不明白为什么会发生这种情况,这不可能是询问部分的格式错误,因为如果是这样,为什么这是在使用它结束后第一次发生这样的事情一年?

4

1 回答 1

3

这是一个错误,当收到非标准位置时,请求如何处理重定向。

服务器返回一个 302 重定向,Location: inquiry.asp?...而 asks 期望它是一个完整的 URL。你可能想提交一个错误报告来询问。


我是怎么找到这个的?一个好的方法是使用代理(例如 mitmproxy)来检查流量。但是 asks 不支持代理。所以我转而使用wireshark,并使用一个程序来提取TLS密钥,以便wireshark可以解密流量。

于 2019-07-18T11:46:12.300 回答