First there are a couple problems with what you posted:
You specify
host
andport
but don't give an exampleurl
, so we can guess that you're using a local deployment for testing and can actually view the requests to the server. I'm not sure what methods you're talking about, but if you're using something akin to Flask for server development, you might not want to send the Authentication as JSON encoded data. There are Authentication headers for a reason, and requests has Authentication handlers for a reason. ;-)You shouldn't specify the
Content-Length
header yourself. requests will do this for you. Beyond that, you're specifying it incorrectly (according to what you posted), so the 404 may be from receiving a header your server doesn't recognize.
Now, there should be no reason to specify verify=False
, and you can specify either cert=pem_file
or verify=pem_file
. Either or both should be fine but you should never use verify=False
.
Finally, the SSLError
that is raised is telling you that the pem
file you're providing is not matching what the server is specifying it. With that in mind, you might want to check your local server's settings. Requests doesn't handle certificate verification itself, but urllib3 provides that. We just set it up based on the parameters you provide. And I doubt this is the fault of urllib3 since it raises an SSLError
which arises from the standard library's ssl
module.
Edit
The explanation is in the documentation specifying a *.pem
file with cert
is invalid. You have to use verify='/path/to/file.pem'
to do this correctly.
Edit #2
To inspect a request that was already sent you can do this:
r = requests.post(...)
r.request
# PreparedRequest('POST', url, ...)
r.request.body
r.request.headers
# etc.
To modify a request before sending you can do the following:
from requests import Request, Session
s = Session()
r = Request('POST', url, datajson_data, headers=headers)
p = r.prepare()
p.body = 'New body'
p.headers = #etc.
s.send(p, verify=pem_file)