Python 为什么请求-响应404或400为无?

Python 为什么请求-响应404或400为无?,python,request,Python,Request,我尝试使用此代码, 因为我没有发送json,所以400 BAD_请求中的请求 但我对结果感到困惑 import requests a= None try: a = requests.post("http://127.0.0.1:8000/api/data/") except : print "exception" if a : print "a is not none" print a.status_code print a.request else:

我尝试使用此代码,
因为我没有发送json,所以400 BAD_请求中的请求
但我对结果感到困惑

import requests
a= None
try:
    a = requests.post("http://127.0.0.1:8000/api/data/")
except :
    print "exception"

if a :
    print "a is not none"
    print a.status_code
    print a.request 
else:
    print "a is none"
    print a.status_code
    print a.content
    print a.request
它打印:

a is none
400
{"Fail":"Format not valid}"}
<PreparedRequest [POST]>
a为无
400
{“失败”:“格式无效”}

如果a是none,为什么我可以打印
a.status\u code,打印a.content,打印a.request

如果a不是none,请检查
a
不是
none
,它可能是一个布尔值计算为
False
的对象。您可以通过查看
bool(a)
返回的内容来再次检查。