微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将我的 python 会话转换为颤振会话

如何解决将我的 python 会话转换为颤振会话

我一直在尝试使用 api https://www.duolingo.com/vocabulary/overview 访问我在 duolingo 上学到的单词。问题是,要使用这个 api,我必须已经登录到 duolingo(经过身份验证)。我在 python 中提出了一个解决方案,使用 requests.sessions() 首先将我的凭据发布到登录页面,然后在同一会话中重新路由到词汇表页面。但是,在尝试在 Flutter 中实现这一点时,我遇到了很多问题。我能够成功地将我的凭据发布到登录页面(并获得成功的 200 响应),但我无法弄清楚如何使用发布请求中的 cookie/令牌成功进入词汇页面。 下面是我的工作 python 代码(为安全起见,删除用户名和密码)

import requests
import json
import ast
headers = {'content-type': 'application/json'}

data = {
    'identifier': 'username','password': 'password',}

with requests.Session() as s:
    url = "https://www.duolingo.com/2017-06-30/login?fields="
    # use json.dumps to convert dict to serialized json string
    s.post(url,headers=headers,data=json.dumps(data))
    r = s.get("https://www.duolingo.com/vocabulary/overview")
    cont = r.content.decode('utf-8')
    print(cont)

这是带有 post 请求和非工作 get 请求的 Flutter 代码


final response = await http.post(
      Uri.parse('https://www.duolingo.com/2017-06-30/login?fields='),headers: <String,String>{
        'Content-Type': 'application/json',},body: jsonEncode(<String,String>{
        'identifier': 'username',}),); // the post returns a success 200 message

    if (response.statusCode == 200) {
      print("success");

      final resp2 = await http.get(
          Uri.parse("https://www.duolingo.com/vocabulary/overview"),); //the get request is supposed to return a json with all my learned words but is instead returning html of the "404 error page)
      }

这里是获取请求的输出

<!doctype html><html dir="ltr"><head><title>Duolingo</title><Meta charset="utf-8"><Meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"><Meta name="robots" content="NOODP"><Meta name="theme-color" content="#eeeeee"><noscript><Meta http-equiv="refresh" content="0; url=/nojs/splash"></noscript><Meta name="apple-mobile-web-app-capable" content="yes"><Meta name="apple-mobile-web-app-status-bar-style" content="black"><Meta name="apple-mobile-web-app-title" content="Duolingo"><Meta name="google" content="notranslate"><Meta name="mobile-web-app-capable" content="yes"><Meta name="apple-itunes-app" content="app-id=570060128"><Meta name="facebook-domain-verification" content="mwudgypvvgl4fekxjk5rpk3eqg7ykt"><link rel="apple-touch-icon" href="//d35aaqx5ub95lt.cloudfront.net/images/duolingo-touch-icon2.png"><link rel="shortcut icon" type="image/x-icon" href="//d35aaqx5ub95lt.cloudfront.net/favicon.ico"><script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" data-document-langua

我对 Flutter 非常陌生,我从未深入研究过会话和 cookie 的工作原理,所以如果我的问题听起来微不足道,我深表歉意。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。