401." str'对象没有属性' read'

时间:2017-07-24 18:58:26

标签: python linux http-status-code-401

以下代码会产生以下错误:

 '响应'对象没有属性' read' 请帮我理解我做错了什么。我确定un和pwd是正确的

user = "un"
password = 'pwd'

datanodes = ["https://server040:25000/"]

for i, datanode in enumerate(datanodes):
    print("Checking {0}: {1}".format(i, datanode))
    try:
        print "trying"
        response = requests.get(datanode + "queries?json",auth=(user, 
password), verify='certs.pem')
        print response
        data = json.loads(response.read())
        print data
        if data["num_waiting_queries"] > 0:
            print(data["num_waiting_queries"])
            for in_flight_query in data["in_flight_queries"]:
                if in_flight_query["waiting"] is True and 
in_flight_query['state'] == "FINISHED":
                    cancel_url = datanode + "cancel_query?query_id=
{}".format(in_flight_query['query_id'])
                    print(cancel_url)

    except IOError as ioe:
        print ioe
    except Exception as e:
        print(e)

我已经尝试过json.load(reponse)和json.loads(response.read())

1 个答案:

答案 0 :(得分:0)

我能够通过添加HTTPDigestAuth并将data = json.loads(response.read())更改为data = response.json()

来解决这些问题。