Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

poor man's patch for issue #630 #633

Merged
merged 1 commit into from

5 participants

@tzuryby
this try catch is a poor man's patch for issue #630
https://github.com/kennethreitz/requests/issues/630
@travisbot

This pull request passes (merged 7125fe5 into de1637c).

@kennethreitz

Thanks!

@kennethreitz kennethreitz merged commit 7813bd8 into kennethreitz:develop
@kennethreitz kennethreitz referenced this pull request from a commit
@kennethreitz cleanup #633 1c0abbd
@mwielgoszewski

Hey Kenneth, I would recommend against wrapping the whole method within a try/except ValueError block. I think my pull request #641 should be sufficient in addressing @tzuryby's issue. If there is another edge case that would raise an exception here, it would be valuable for us to understand why it did so. Catching the exception and continuing would prevent us or the developer from even knowing there was an issue with the URI.

@piotr-dobrogost

I would recommend against wrapping the whole method within a try/except ValueError block

Agree.

@tzuryby

that's a far better fix than my catch-all approach, no doubt.
that's why I called it "poor man's patch.." ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 14 deletions.
  1. +21 −14 requests/utils.py
View
35 requests/utils.py
@@ -407,22 +407,29 @@ def stream_untransfer(gen, resp):
def unquote_unreserved(uri):
- """Un-escape any percent-escape sequences in a URI that are unreserved
- characters.
- This leaves all reserved, illegal and non-ASCII bytes encoded.
- """
- parts = uri.split('%')
- for i in range(1, len(parts)):
- h = parts[i][0:2]
- if len(h) == 2:
- c = chr(int(h, 16))
- if c in UNRESERVED_SET:
- parts[i] = c + parts[i][2:]
+ '''
+ this try catch is a poor man's patch for issue #630
+ https://github.com/kennethreitz/requests/issues/630
+ '''
+ try:
+ """Un-escape any percent-escape sequences in a URI that are unreserved
+ characters.
+ This leaves all reserved, illegal and non-ASCII bytes encoded.
+ """
+ parts = uri.split('%')
+ for i in range(1, len(parts)):
+ h = parts[i][0:2]
+ if len(h) == 2:
+ c = chr(int(h, 16))
+ if c in UNRESERVED_SET:
+ parts[i] = c + parts[i][2:]
+ else:
+ parts[i] = '%' + parts[i]
else:
parts[i] = '%' + parts[i]
- else:
- parts[i] = '%' + parts[i]
- return ''.join(parts)
+ return ''.join(parts)
+ except:
+ return uri
def requote_uri(uri):
Something went wrong with that request. Please try again.