Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_params is now ignored if not set #45

Merged
merged 1 commit into from
Nov 30, 2020
Merged

get_params is now ignored if not set #45

merged 1 commit into from
Nov 30, 2020

Conversation

joker234
Copy link
Member

@joker234 joker234 commented Jul 9, 2020

When the last example from the readme is tried, this error occurs.

client = ors.Client(base_url=host)
resp = client.request(
    url=f'/v2/directions/{profile}/{format}',
    post_json={
        'coordinates': coords
    })

Error:

  …
  File "$HOME/.local/lib/python3.8/site-packages/openrouteservice/client.py", line 163, in request
    authed_url = self._generate_auth_url(url,
  File "$HOME/.local/lib/python3.8/site-packages/openrouteservice/client.py", line 267, in _generate_auth_url
    return path + "?" + _urlencode_params(params)
  File "$HOME/.local/lib/python3.8/site-packages/openrouteservice/client.py", line 330, in _urlencode_params
    params = [(key, _normalize_for_urlencode(val)) for key, val in params]
TypeError: 'NoneType' object is not iterable

If the parameter get_params={} is added, everything works as expected. The fix in this PR skips the urlencode line and just returns the path when the params are none. A test is added as well.

the client no longer tries to urlencode None
@coveralls
Copy link

coveralls commented Jul 9, 2020

Pull Request Test Coverage Report for Build 134

  • 2 of 2 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+1.3%) to 95.247%

Totals Coverage Status
Change from base Build 131: 1.3%
Covered Lines: 521
Relevant Lines: 547

💛 - Coveralls

@joker234
Copy link
Member Author

joker234 commented Jul 9, 2020

Alternatives would be to

  1. change the readme example, or
  2. catch the error in:
    def _urlencode_params(params):
    """URL encodes the parameters.
    :param params: The parameters
    :type params: list of key/value tuples.
    :rtype: string
    """
    # urlencode does not handle unicode strings in Python 2.
    # Firstly, normalize the values so they get encoded correctly.
    params = [(key, _normalize_for_urlencode(val)) for key, val in params]
    # Secondly, unquote unreserved chars which are incorrectly quoted
    # by urllib.urlencode, causing invalid auth signatures. See GH #72
    # for more info.
    return requests.utils.unquote_unreserved(urlencode(params))

@nilsnolde
Copy link
Contributor

I'll just merge now, hope someone of the team will soon (at least eventually..) maintain this..

@nilsnolde nilsnolde merged commit 859f83b into master Nov 30, 2020
@joker234 joker234 deleted the get-params-fix branch November 30, 2020 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants