2

I'm coding in python, using version 2.6, working with the Uber API, and when I try to import the library uber_rides.auth it throws this error:

Traceback (most recent call last):
  File "C:\Inetpub\vhosts\underdevelopment.biz\httpdocs\web\webtemp3\uber\socket.py", line 4, in <module>    
    from uber_rides.auth import AuthorizationCodeGrant
  File "C:\Inetpub\vhosts\underdevelopment.biz\httpdocs\web\webtemp3\uber\uber_rides\auth.py", line 133
    query_params = [qp: query_params[qp][0] for qp in query_params]
                      ^
SyntaxError: invalid syntax

The original code of my script is this:

print('Content-Type: text/plain')
print('')
from uber_rides.auth import AuthorizationCodeGrant
def main():
    auth_flow = AuthorizationCodeGrant(
        'xxxxxx-xxxxxxx',
        'xxxxx-xxxxx',
        'xxx-xxxxxxxxx',
        '',
    )
    auth_url = auth_flow.get_authorization_url()

if __name__ == "__main__":
    main()

It seems the error is from the library but I can't find it yet.

mhatch
  • 4,441
  • 6
  • 36
  • 62
  • 1
    Yes, the error is in the library. They used invalid syntax. It may be they meant to use a dict comprehension instead. – Martijn Pieters Mar 25 '16 at 14:36
  • 1
    Where did you get the files from? Looking at [the GitHub source](https://github.com/uber/rides-python-sdk/blob/master/uber_rides/auth.py#L133) the syntax is correct there. It also was never wrong, that's the initial commit. – Martijn Pieters Mar 25 '16 at 14:39

1 Answers1

2

Yes, that's invalid Python syntax. However, it is not clear how you ended up with that file.

Someone or something altered that file. That's not the original source code as distributed by Uber, where that line uses the correct syntax for a dictionary comprehension:

query_params = {qp: query_params[qp][0] for qp in query_params}

Re-install the project, the error is not there upstream.

Note that the above syntax is only available in Python 2.7 and up. You could try to replace it with a dict() call with a generator expression, see Alternative to dict comprehension prior to Python 2.7:

query_params = dict((qp, query_params[qp][0]) for qp in query_params)

Take into account that there may be other issues with the code, upgrading to Python 2.7 is probably the better option.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • I changed the code but Throws an error again: Traceback (most recent call last): File "C:\Inetpub\vhosts\underdevelopment.biz\httpdocs\web\webtemp3\uber\socket.py", line 4, in from uber_rides.auth import AuthorizationCodeGrant File "C:\Inetpub\vhosts\underdevelopment.biz\httpdocs\web\webtemp3\uber\uber_rides\auth.py", line 133 query_params = {qp: query_params[qp][0] for qp in query_params} ^ SyntaxError: invalid syntax – Arturo Vasquez Mar 25 '16 at 14:54
  • 1
    @ArturoVasquez: You are using Python 2.6. The library requires Python 2.7 or newer. – Martijn Pieters Mar 25 '16 at 14:56