Giter Site home page Giter Site logo

python-sdk's People

Contributors

adolfoportilla avatar allisonc07 avatar aytekin-smartcar avatar bdr99 avatar bharathguna avatar charlottekosche avatar clach04 avatar esonmez avatar evanpeterson1324 avatar gregchan avatar gurpreetatwal avatar hhovsepi avatar jacobandrewsmith92 avatar karthikbhaskara avatar mdheri avatar morgannewman avatar naomiperez avatar nbry avatar robinjayaswal avatar rsimari avatar s-ashwinkumar avatar sankethkatta avatar theodorewahle avatar zespinosa97 avatar zzggbb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-sdk's Issues

Update documentation

The documentation is out of date and also needs some fixes.

  1. Wrong env vars for client secret and redirect uri
export SMARTCAR_CLIENT_ID='<your client id>'
export SMARTCAR_CLIENT_ID='<your client secret>'
export SMARTCAR_CLIENT_ID='<your redirect URI>'
  1. The examples uses the odometer function but it does not create the scope for that reading.
  2. vehicles = smartcar.get_vehicle_ids(<access_token>) method should be replaced by get_vehicles.

BUG: retry_after missing in Rate Limit SmartcarExceptions that occur on individual endpoints when making a batch call

I am using smartcar==6.10.1 python package.

When calling the batch function passing a list of endpoints, if a rate limit smartcar.exceptions.SmartcarException occurs, the exception is always missing the retry_after key, which is supposed to be taken from the Retry-After header.

Below is one example where I made a request which gets rate limited and returns a Retry-After header, but the exception does not have the retry_after key. The request id is: 58ae060d-0a03-40a4-a628-3b699b479cd7
I figured out why the problem is happenning, I am happy to open a PR for the fix if I am on the right track here:

When the batch function is called, each passed endpoint's response is checked whether it has a HTTP status different than 200. Of course the endpoint with the request-id given above has a status of 429 (rate limit), and the batch function invokes the exception factory, constructs the exception and assigns it to be raised when that specific attribute is later called on the batch result object. The problem is in the batch function (which is found in vehicle.py:400), when it invokes exception_factory, it passes the headers of the batch request itself, not the headers of the individual endpoint that failed. I can actually see in code that here (vehicle.py:457):
sc_exception = sce.exception_factory(code, headers, body)
headers are missing the Retry-After header, but res_dict.get("headers") actually is {'Retry-After': 80}
res_dict is the individual response for each of the invoked endpoint within the batch, not the batch's response (which is always 200)
So I tested when I change vehicle:457 from:
sc_exception = sce.exception_factory(code, headers, body)
to:
sc_exception = sce.exception_factory(code, {**headers, "Retry-After": res_dict.get("headers").get("Retry-After")}, body)
My smartcar.exceptions.SmartcarException object has a present retry_after attribute.

redirect_uri for an autonomous backend app

Hello,

this is not an issue per se but rather a question about something I couldn't find in the docs. They describe in much detail how an app gets authenticated when the user logs in via a web page or mobile app, and then "user’s browser is redirected to a specified redirect_uri." This doesn't work for me though. I'm developing a fully autonomous back-end app that won't have a front-end and which must work without the user who would manually log in and without a browser or another UI object. I wasn't able to find docs that would describe how to proceed in such a situation. Here's where I am now: I created a client and obtained auth_url as described in the docs:

client = smartcar.AuthClient(client_ID, client_secret, client_secret, redirect_uri, scope)
auth_url = client.get_auth_url()

My redirect_uri points to an URL at my server at which my app is listening and will parse a request when received. What should I do now to ask smartcar to send that request to my redirect_uri? I tried r = requests.get(auth_url) but I've got <Response [400]> / Bad request. No request was sent to redirect_uri. Please advise.

Thank you,

Greg (dev ID 8f272ab7-e2ae-428b-83cc-bdfb6c44edce)

Codecov Integration

Since this is a FOSS project, I propose adding Codecov integration (free). This will give developers who use this package a higher level of confidence when shipping code.

This can easily achieved by creating a workflow using GitHub actions adding codecov to after_success step in .travis.yml, which will run a coverage branch analysis on each PR. We can easily add a badge to the README and give full visibility of the project code coverage.

I can open up a PR

Note: this repo will need to be enabled via codecov dashboard

expired() method missing

There is no equivalent of the Smartcar.prototype.expired method on the python-sdk. (I think this is missing from the java sdk as well)

This would be necessary to know whether or not to refresh a token. This also requires the creation of a created_at field on the access.

flash_headlight throws ResourceNotFound exception

Upon calling flash_headlight with most recent python sdk as of 12/16/16:

 File "/mnt/c/Users/robinjayaswal/Documents/GitHub/iotUIClient/iot-lambda-function/smartcar/vehicle.py", line
157, in flash_headlight
    return self.api.action("lights/headlight", "FLASH")
  File "/mnt/c/Users/robinjayaswal/Documents/GitHub/iotUIClient/iot-lambda-function/smartcar/api.py", line 27,
in action
    return requester.call('POST', url, json=json, headers=self.auth)
  File "/mnt/c/Users/robinjayaswal/Documents/GitHub/iotUIClient/iot-lambda-function/smartcar/requester.py", lin
e 20, in call
    raise E.ResourceNotFoundException(response)
smartcar.exceptions.ResourceNotFoundException: The requested resource was not found.

exchange_code and exchange_token not working

OAuth uses x-www-form-urlencoded encoding for the body parameters. But both methods are using params, which put the options into the url instead of the body. They should be using data instead to send form data.

In addition, it does not seem as though the Basic Authentication headers are being sent with the client_id/client_secret either.

Test with Travis CI

Travis CI is now enabled for this repository, you should be able to setup a .travis.yml file. Make sure to test against all versions of python we care about.

KeyError thrown when 'message' not in error

The message property is not returned on some errors. OAuth errors, for example use error and error_description properties. In L3 of exceptions.py we have:

self.message = response.json()['message']
// A safer .get() might be better
self.message = response.json().get('message')

Instead, we should handle for OAuth exceptions as well, and have a default message, should the other keys not exist.

Add remote start/stop to API

Probably one of the most useful features aside from lock/unlock would be start/stop. Anecdotally, these are the two features I find the most useful in-app and it would be very helpful to have remote start available via the API.

readme sample errors

vehicle = smartcar.Vehicle(vehicle_id, access_token)
odometer = vehicle.odometer()['data']['odometer']

Errors with:

KeyError: 'odometer'

Wrap simplejson.errors.JSONDecodeError inside SmartcarException

On September 10th, 2020 between 7 p.m. and 8 p.m. CEST we faced issues when using Smartcar’s API to communicate with Tesla vehicles. After five minutes a simplejson.errors.JSONDecodeError exception was thrown.

Wouldn’t it be nicer to have that exception wrapped in a SmartcarException with additional information about what caused the error?

  File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/smartcar/vehicle.py", line 311, in batch
    response = self.api.batch(requests)
  File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/smartcar/api.py", line 79, in batch
    return requester.call('POST', url, json=json, headers=headers)
  File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/smartcar/requester.py", line 31, in call
    body = response.json()
  File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/requests/models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/simplejson/decoder.py", line 370, in decode
    obj, end = self.raw_decode(s)
  File "/opt/.virtualenvs/django22/lib/python3.7/site-packages/simplejson/decoder.py", line 400, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.