【问题标题】:Converting cURL call with encode to python request将带有编码的 cURL 调用转换为 python 请求
【发布时间】:2016-08-06 15:02:13
【问题描述】:

现在在这被标记为重复和否决之前,我已经尝试了所有其他链接(见下文),但它们没有帮助。

converting curl call to python requests

Convert cURL request to Python-Requests request

我正在进行的 cURL 调用是(在 .sh 文件中存在 $ 插值)

COOKIE_JAR=./program.cookies
LOGIN_URL= 'URL'
USER_ID = 'USERID'
PASSWORD = 'password'
VIEWSTATE = 'long string of text'

$(curl"$LOGIN_URL"-L -b "$COOKIE_JAR" -c "$COOKIE_JAR"
--data-urlencode "__VIEWSTATE=$viewstate" --data-urlencode "userid=$USER_ID" 
--data-urlencode "password=$PASSWORD") || printf >2 "failed to get token:\n%s" 
"$token" && printf "your token is:\n%s\n" "$token"

如何将其翻译成 python 请求表单?任何帮助将不胜感激!! :)

【问题讨论】:

  • “他们没有帮助”是什么意思?服务器没有得到正确的数据或者你得到一个错误?
  • 因为它的形式不同,因为我也必须处理 cookie
  • 嘿,感谢您的帮助,没关系,我搞定了!不需要饼干 :)

标签: python curl


【解决方案1】:

所以我设法让它工作,如果有人需要它:

 payload = {
        'userid': USERID,
        'password': PASSWORD,
        '__VIEWSTATE':viewstate # defined earlier
    }
    with requests.Session() as s:
        x = s.get(URL, params=payload,headers=headers)
        token = x.text

毕竟不需要饼干!

【讨论】:

    猜你喜欢
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    • 2016-01-30
    • 2020-03-18
    • 2023-04-02
    相关资源
    最近更新 更多