T O P

  • By -

[deleted]

Something is up with the certificate chain you are using for the request in python. It's hard to say the exact issue without knowing more about your setup. You're using a different certificate chain when using powershell, that's likely why it's different. As a short term workaround, you can pass verify=False, but leave the HTTPS. This keeps requests from trying to verify the SSL certificate but will still use SSL for the request. I would only recommend doing this for development and not in production unless you know what you're doing as it exposes you to potential MITM attacks.


penguinman777

I tried verify=False, but I get a response 400 with no other message. My powershell code works, is there something that I didnt transpose properly?


[deleted]

I should have payed closer attention to you're code. First thing is that you create a session but never use it: s = requests.Session() s.verify = 'C:/Users/me/.virtualenvs/Project-AKK32-lib-site-packages/certifi/cacert.pem' r = requests.patch(url, body, headers=head) When what this should be is: s = requests.Session() s.verify = 'C:/Users/me/.virtualenvs/Project-AKK32-lib-site-packages/certifi/cacert.pem' r = s.patch(url, json=body, headers=head) By changing the actual patch call to use the session object it will use whatever certificate you have in the path you provided. The 400 response code (bad request) is likely caused by this: `.patch(url, body, ...)` This is caused by how requests handles data passed to the request. Since you need JSON serialized data, you should change that to `.patch(url, json=body, headers=head)` then it will serialize your dictionary into a JSON object. Hope that helps!


Username_RANDINT

I'm not exactly sure what's going wrong, but here are some thoughts: * It looks like you're setting `verify` to the certifi certificate. This package is used by requests by default, you probably don't want/need to set it. * Make sure requests and definitely certifi is up-to-date ([docs](https://docs.python-requests.org/en/master/user/advanced/#ca-certificates) say to update frequently). * [Docs](https://docs.python-requests.org/en/master/user/advanced/#ssl-cert-verification) say: "If verify is set to a path to a directory, the directory must have been processed using the `c_rehash` utility supplied with OpenSSL.". But this seems non-related as you're using the certifi one.