I'm developing a QGIS plugin that needs to send https request to an API. I have to use urllib2 (see below if you want to know why I don't just use the requests package)
The first request I need to make is a POST one, with id in the header, so the API would grant me an access token (according to the OAuth2 protocol) I have this portion of script, that works when executed alone, but doesn't as soon as I integrate it in my QGIS plugin script, it gives me a weird URLError (code 10054 : the distant host had to close a connexion) but I suspect QGIS doesn't event send the request at all, for it isn't an answer that the API gives.
import urllib
import urllib2
myIDs = "Basic hjNjkJCOHdrUncN4RVV"
url = 'https://id.mygreatapi.com/oauth/token'
values = {"grant_type":"client_credentials"}
data = urllib.urlencode(values)
header = {"Authorization": myIDs}
req = urllib2.Request(url,data, header)
try:
handle = urllib2.urlopen(req)
content = handle.read()
print(content)
except urllib2.HTTPError as e:
code = e.code
texte = e.read()
print(code)
print(texte)
Note that when I copy a valid token into my QGIS plugin script and then make GET requests to the API using http, it works. So I guess the problem comes from the https.
Any ideas why QGIS wouldn't send this request ?
Why don't I use requests library ? It is necessary that the plugin could be installed by anyone (especially somebody without admin rights on his computer, and no programming knowledge whatsoever) so I can't expect people to use their OSGeo and use pip install. The solutions proposed in this page being totally out of my competences, I considered that I have to stick with the packages that are built-in the python version QGIS uses.
So the problem must be the ssl certificate signature verification. The organism that has signed our API certificate must be absent of the list used by QGIS.
– El Theo Jun 30 '16 at 15:43