使用Paw进行基本HTTP身份验证

时间:2015-11-15 01:22:41

标签: python python-requests paw-app

我有一个小的python脚本,可以使用以下代码正确访问我的API

import requests
auth = requests.auth.HTTPDigestAuth(user, password)
furl="http://10.101.0.203:8080/imcrs/plat/res/device"
r = requests.get(f_url, auth=auth )

在这种情况下,auth对象完美运行(它能够发送GER请求,并且auth对象能够成功进行身份验证,并且我通过HTTP 200响应获得预期内容)

查看PAW生成的python代码

def send_request():
    # My API
    # GET http://10.101.0.203:8080/imcrs/plat/res/device

    try:
        response = requests.get(
            url="http://10.101.0.203:8080/imcrs/plat/res/device",
            params={
                "resPrivilegeFilter": "false",
                "start": "0",
                "size": "10",
                "orderBy": "id",
                "desc": "false",
                "total": "false",
            },
            headers={
                "AuthorizationBasic Og==": "Basic YWRtaW46YWRtaW4=",
                "Cookie": "JSESSIONID=D1B20BF4BB2FC9F458C8A45821FE0BDB",
            },
        )
        print('Response HTTP Status Code: {status_code}'.format(
            status_code=response.status_code))
        print('Response HTTP Response Body: {content}'.format(
            content=response.content))
    except requests.exceptions.RequestException:
        print('HTTP Request failed')

似乎PAW正在编码auth字符串,然后在标头中发送,导致立即401错误。

标题是否与上面创建的auth对象相同?试图弄清楚为什么这不起作用。

1 个答案:

答案 0 :(得分:1)

在您正在使用的HTTPDigestAuth工作python代码中,这与Basic auth paw目前不支持HTTPDigestAuth不同。