Closed snarfed closed 5 years ago
@snarfed When I use the backported urllib (indirectly via python sendgrid client), I get this error in local development:
le "/Users/jacob/workspace/gae/src/sitepackages/prod/python_http_client/client.py", line 172, in _make_request
return opener.open(request, timeout=timeout)
File "/Users/jacob/workspace/gae/src/sitepackages/prod/future/backports/urllib/request.py", line 494, in open
response = self._open(req, data)
File "/Users/jacob/workspace/gae/src/sitepackages/prod/future/backports/urllib/request.py", line 512, in _open
'_open', req)
File "/Users/jacob/workspace/gae/src/sitepackages/prod/future/backports/urllib/request.py", line 466, in _call_chain
result = func(*args)
File "/Users/jacob/workspace/gae/src/sitepackages/prod/future/backports/urllib/request.py", line 1326, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Users/jacob/workspace/gae/src/sitepackages/prod/future/backports/urllib/request.py", line 1287, in do_open
raise URLError(err)
URLError: <urlopen error [Errno 13] Permission denied>
It works fine on production app engine.
The http client has this code:
try:
# Python 3
import urllib.request as urllib
from urllib.parse import urlencode
from urllib.error import HTTPError
except ImportError:
# Python 2
import urllib2 as urllib
from urllib2 import HTTPError
from urllib import urlencode
If I force it to urllib2, then it works fine.
Have you seen this issue?
@jacobg heh, yes, i hit that too: https://github.com/snarfed/webutil/commit/f71e1cb479d2218bc3b690384868d90171dc7d80
the backported urllib
doesn't support SSL - http://python-future.org/imports.html#aliased-imports - so if you're seeing this on https URLs, that's probably why. try from future.moves.urllib.request import urlopen
instead.
@snarfed haha thanks! This monkeypatch fixes it:
def _fix_sendgrid_http_client():
# force sendgrid's http client to use urllib2, not future urllib.
# future urllib doesn't work in local development.
# https://github.com/PythonCharmers/python-future/issues/320#issuecomment-412174717
import urllib2 as urllib
from urllib2 import HTTPError
from urllib import urlencode
from python_http_client import client
client.urllib = urllib
client.HTTPError = HTTPError
client.urlencode = urlencode
first off, thanks for future! it's hugely valuable.
i noticed that the aliases for
http.client
don't work in google app engine, at least not indev_appserver.py
. (#231 is an older, similar app engine compability issue.) here's the exception:to reproduce, create these two files:
app.yaml
:app.py
:then create the virtualenv, run the server:
and open http://localhost:8080/ in your browser.
i'm on future 0.16.0 and gcloud 184.0.0. details: