Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Unable to use requests for https connections
-
I'm trying to build a mobile client for the alpaca markets trading api, the official sdk from alpaca (alpaca-py) installs via pip through stash but it also requires the (alpaca-trade-api) which fails install due to dependencies which require c compilation.
As a workaround I was going to build my own framework that just uses the raw api calls through the requests module but I keep getting SSL errors. I assume it has to do with iOS not trusting the server side certificate, is there any known workaround for this?
Even more strange is if I build the exact same api call through shortcuts using the "get contents of url" block I get a server error (I assume it's a certificate error) but if I use a shortcut provided by the Rest app from the AppStore it validates and I get the expected response.
As a side note I installed Pyto and get the exact same error. The Rest app must be providing its own certificate, is there a way to force pythonista to do the same??
-
@kizik what SSL error are you getting, specifically ?
-
@kizik You may want to try something like this.
import urllib3 urllib3.disable_warnings() import requests url = 'https://jsonplaceholder.typicode.com/posts/1' data = {'somekey': 'somedata'} try: r = requests.get(url, headers={}, params=data, verify=False) response = r.json() print(response) except: print("Exception u: %s" % str(sys.exc_info()))
-
I have to admit, it was 100% user error, my api keys weren't being pulled in from my .env file properly. I restructured my .env file, fixed how I was calling the headers and everything seems to be working as expected now.
Appreciate the feedback though. Just had to step away for a minute and come back with some fresh eyes.