CartoDB / carto-python

CARTO Python client
https://carto.com
BSD 3-Clause "New" or "Revised" License
154 stars 62 forks source link

Python 3.x compatible (error on OAuth) #13

Closed jgsogo closed 9 years ago

jgsogo commented 9 years ago

These are some changes to make this package compatible with Python 3.

I've only tested Import API. In order to work with OAuth, python-oauth2 must be upgraded to py3 first.

jgsogo commented 9 years ago

With the release 1.9 of python-oauth2 (now in Pypi), CargoDBOAuth works with python3 too, nevertheless it raises an exception when calling CartoDB servers (any docs about this?):

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "E:\_VirtualEnvs\adif-scraper\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "E:\_VirtualEnvs\adif-scraper\lib\site-packages\django\core\management\__init__.py", line 330, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "E:\_VirtualEnvs\adif-scraper\lib\site-packages\django\core\management\base.py", line 393, in run_from_argv
    self.execute(*args, **cmd_options)
  File "E:\_VirtualEnvs\adif-scraper\lib\site-packages\django\core\management\base.py", line 444, in execute
    output = self.handle(*args, **options)
  File "E:\_VirtualEnvs\adif-scraper\adif-scraper\adif\management\commands\dump_stations.py", line 65, in handle
    success = upload_to_cartodb(filename, CARTODB_API_KEY, CARTODB_DOMAIN)
  File "E:\_VirtualEnvs\adif-scraper\adif-scraper\adif\utils\cartodb.py", line 24, in upload_to_cartodb
    fi.run()
  File "E:\_VirtualEnvs\adif-scraper\lib\site-packages\cartodb-0.8.1-py3.4.egg\cartodb\imports.py", line 88, in run
  File "E:\_VirtualEnvs\adif-scraper\lib\site-packages\cartodb-0.8.1-py3.4.egg\cartodb\imports.py", line 49, in req
  File "E:\_VirtualEnvs\adif-scraper\lib\site-packages\cartodb-0.8.1-py3.4.egg\cartodb\cartodb.py", line 146, in get_response_data
cartodb.cartodb.CartoDBException: {'imports': 'invalid user max_concurrent_import_count (must be positive integer)'}
danicarrion commented 9 years ago

@jgsogo this looks like a platform problem. can you confirm this is still happening?

also, before accepting your pull request, you need to sign our contributor agreement https://cartodb.com/contributing/ i'm really sorry for the inconvenience

jgsogo commented 9 years ago

I've just sent the email for the CLA ;D

About the max_concurrent_import_count error, it is still raised. It seems to be related to source code in this file from CartoDB/cartodb repo (it is the only search result in Google). May I open an issue there or do you think it is originated somewhere else?

danicarrion commented 9 years ago

what's the name of the cartodb account you're using?

jgsogo commented 9 years ago

This is the config data I'm using:

    user =  'jgsogo@gmail.com'
    password =  '<password>'
    CONSUMER_KEY='<consumer-secret-key>'
    CONSUMER_SECRET='<consumer-secret>'
    cartodb_domain = 'jgsogo'
    cl = CartoDBOAuth(CONSUMER_KEY, CONSUMER_SECRET, user, password, cartodb_domain)
danicarrion commented 9 years ago

Our Import API has a broken xAuth support, that's why we don't officially claim to support xAuth there. Can you try with your API key?

jgsogo commented 9 years ago

The ImportAPI works ok (commits on 3rd Sept.), and is the one I'm using; but now that oauth2 has been ported to Python3 (oauth2>=1.9) I also make the neccesary changes to this package to "work" with it.

jgsogo commented 9 years ago

CLA signed and sent by email, may I/you wait for confirmation?

vhamer commented 9 years ago

Thank you Javier! We have received your CLA. I am reassigning to @danicarrion for next steps. Thanks for your contribution.

danicarrion commented 9 years ago

With python3 I get some warnings about the import file & sockets not being properly closed. I'll issue a ticket and fix it after we merge your PR.

jgsogo commented 9 years ago

I like it this way:

  1. Raise error if available (it is the expected behaviour)
  2. Raise errors ("not expected", we don't know how to solve it)
  3. Otherwise raise response.text to give information to the user.
danicarrion commented 9 years ago

thanks!!!