Bug 994602

Summary: AttributeError: 'MockRequest' object has no attribute 'origin_req_host'
Product: [Fedora] Fedora Reporter: Jim Minter <jminter>
Component: python-requestsAssignee: Arun S A G <sagarun>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: high Docs Contact:
Priority: unspecified    
Version: 19CC: rbean, sagarun
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-09-23 18:58:53 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jim Minter 2013-08-07 15:08:11 UTC
I'm getting the following error and traceback with latest python3-requests and python3 on F19:

Traceback (most recent call last):
  File "/usr/lib/python3.3/site-packages/requests/sessions.py", line 310, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python3.3/site-packages/requests/sessions.py", line 279, in request
    resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
  File "/usr/lib/python3.3/site-packages/requests/sessions.py", line 374, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.3/site-packages/requests/adapters.py", line 219, in send
    r = self.build_response(request, resp)
  File "/usr/lib/python3.3/site-packages/requests/adapters.py", line 106, in build_response
    extract_cookies_to_jar(response.cookies, req, resp)
  File "/usr/lib/python3.3/site-packages/requests/cookies.py", line 105, in extract_cookies_to_jar
    jar.extract_cookies(res, req)
  File "/usr/lib64/python3.3/http/cookiejar.py", line 1647, in extract_cookies
    if self._policy.set_ok(cookie, request):
  File "/usr/lib64/python3.3/http/cookiejar.py", line 931, in set_ok
    if not fn(cookie, request):
  File "/usr/lib64/python3.3/http/cookiejar.py", line 952, in set_ok_verifiability
    if request.unverifiable and is_third_party(request):
  File "/usr/lib64/python3.3/http/cookiejar.py", line 707, in is_third_party
    if not domain_match(req_host, reach(request.origin_req_host)):
AttributeError: 'MockRequest' object has no attribute 'origin_req_host'

Upstream, this error is noted at https://github.com/kennethreitz/requests/issues/1379

The upstream recommendation is to upgrade to Requests to 1.2.1 or later.  Can we rebase to the latest release 1.2.3?

Comment 1 Jim Minter 2013-08-07 16:30:38 UTC
For visitors looking for an insecure hack to work around this, try adding the following code to your application:

# https://github.com/kennethreitz/requests/issues/1379
import http.cookiejar
http.cookiejar.is_third_party = lambda request: False

Comment 2 Ralph Bean 2013-08-20 03:50:53 UTC
Sure, let's give it a try.

So many things rely on python-requests... I'll try to let it sit in updates-testing a little longer than usual.

Comment 3 Fedora Update System 2013-08-20 04:03:35 UTC
python-requests-1.2.3-2.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/python-requests-1.2.3-2.fc19

Comment 4 Jim Minter 2013-08-22 17:45:33 UTC
Oh dear, this isn't good.

Trying python3-requests-1.2.3-2.fc19, I've found that it's not automatically un-gzipping content received from remote servers like it used to.  Given (as Ralph mentioned) the number of people relying on python-requests, I think that's a show-stopper.

The issue is down to a combination of:
(a) commit https://github.com/kennethreitz/requests/commit/59f916ca4a6a8e55528988cfc1bee445e71c4602 removing functionality in favour of using urllib3 instead, and
(b) the replacement urllib3 functionality being broken in the version of urllib3 that we currently ship.  Specifically, in HTTPResponse.read(), 

...
            if amt is None:
                # cStringIO doesn't like amt=None
                data = self._fp.read()
            else:
                return self._fp.read(amt)

            try:
                if decode_content and decoder:
                    data = decoder(data)
            except (IOError, zlib.error):
...

the return statement shouldn't be there as it prevents the gzip decoder from running.  This is fixed upstream (I've checked that python3-pip install --upgrade urllib3 makes things act as expected).

I'd now suggest the following:
- for F20, rebase python3-requests /and/ python3-urllib to latest upstream
- for F19, reject python3-requests-1.2.3-2, and do one of the following, depending on appetite for risk:
  - rebase python3-requests /and/ python3-urllib to latest upstream, OR
  - try rebasing python3-requests ONLY to 1.2.1 or 1.2.2 (thus missing the commit mentioned above), OR
  - do nothing!

Comment 5 Ralph Bean 2013-08-22 18:09:48 UTC
Well, as long as the updates for python3-requests and python3-urllib go out together.. and as long as we keep them in updates-testing for a hefty amount of time: I think I'm ok with updating them both to the latest upstream in F19.

Comment 6 Fedora Update System 2013-08-22 21:17:31 UTC
python-urllib3-1.7-1.fc19,python-requests-1.2.3-3.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/python-urllib3-1.7-1.fc19,python-requests-1.2.3-3.fc19

Comment 7 Jim Minter 2013-08-26 14:21:34 UTC
Tested and all works for me -- thanks!

I wonder if it might be worth putting
  Requires: python-urllib3 >= 1.7
and 
  Requires: python3-urllib3 >= 1.7
in the relevant parts of the requests spec file?

Comment 8 Ralph Bean 2013-08-26 14:59:02 UTC
Yes, that sounds smart.

Comment 9 Fedora Update System 2013-08-26 15:39:10 UTC
python-urllib3-1.7-2.fc19,python-requests-1.2.3-4.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/python-urllib3-1.7-2.fc19,python-requests-1.2.3-4.fc19

Comment 10 Fedora Update System 2013-08-29 02:15:45 UTC
python-requests-1.2.3-5.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/python-requests-1.2.3-5.fc19

Comment 11 Fedora Update System 2013-08-29 03:11:40 UTC
python-urllib3-1.7-3.fc19 has been submitted as an update for Fedora 19.
https://admin.fedoraproject.org/updates/python-urllib3-1.7-3.fc19

Comment 12 Jim Minter 2013-08-30 09:55:52 UTC
All works for me.  I'll report back if I encounter any issues with the new RPMs.  Thanks again.

Comment 13 Fedora Update System 2013-09-17 00:32:58 UTC
python-urllib3-1.7-3.fc19 has been pushed to the Fedora 19 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 14 Fedora Update System 2013-09-22 04:25:53 UTC
python-requests-1.2.3-5.fc19 has been pushed to the Fedora 19 stable repository.  If problems still persist, please make note of it in this bug report.