Coder Social home page Coder Social logo

api-py's People

Contributors

brimoor avatar himapatel2011 avatar hoddr avatar jinyixin621 avatar lethosor avatar mattphotonman avatar mikejeffers avatar tylerganter avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

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

Forkers

mangalbhaskar

api-py's Issues

Documentation around job request upload parameters is unclear

This simple job request does not result in a started job:

job_request = JobRequest("vehicle-tracker")
job_request.set_input("file", data_id=data_id)
job_request.set_parameter("job_name", "tracker-test")
job_request.set_parameter("auto_start", True)

Expose batch requests across users for an App Admin

As a scoop application, we currently have to iterate through each user individually to request information regarding jobs and data. It would be nice to request all jobs for all users of the application or batch query a list of job ids.

upload_analytic method raises a NameError

from voxel51.api import API
api = API()
api.upload_analytic("/path/to/analytic.json")

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-1f6d68783277> in <module>
----> 1 api.upload_analytic("/path/to/analytic.json")

~/api-py/voxel51/api.py in upload_analytic(self, doc_json_path)
    162         '''
    163         endpoint = self.base_url + "analytics"
--> 164         filename = os.path.basename(path)
    165         mime_type = _get_mime_type(doc_json_path)
    166         with open(doc_json_path, "rb") as df:

NameError: name 'path' is not defined

OverflowError when using `upload_analytic_image` method

from voxel51.api import API
api = API()
api.upload_analytic("/path/to/analytic.json")
api.upload_analytic_image("analytic id", "/path/to/image.tar.gz", "gpu")

---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-9-2c6500bb68c5> in <module>
----> 1 api.upload_analytic_image("analytic id", "/path/to/image.tar.gz", "gpu")

~/api-py/voxel51/api.py in upload_analytic_image(self, analytic_id, image_tar_path, image_type)
    191             files = {"file": (filename, df, mime_type)}
    192             res = self._requests.post(
--> 193                 endpoint, headers=self._header, files=files, params=params)
    194         _validate_response(res)
    195 

~/myenv/lib/python3.5/site-packages/requests/api.py in post(url, data, json, **kwargs)
    114     """
    115 
--> 116     return request('post', url, data=data, json=json, **kwargs)
    117 
    118 

~/myenv/lib/python3.5/site-packages/requests/api.py in request(method, url, **kwargs)
     58     # cases, and look like a memory leak in others.
     59     with sessions.Session() as session:
---> 60         return session.request(method=method, url=url, **kwargs)
     61 
     62 

~/myenv/lib/python3.5/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    522         }
    523         send_kwargs.update(settings)
--> 524         resp = self.send(prep, **send_kwargs)
    525 
    526         return resp

~/myenv/lib/python3.5/site-packages/requests/sessions.py in send(self, request, **kwargs)
    635 
    636         # Send the request
--> 637         r = adapter.send(request, **kwargs)
    638 
    639         # Total elapsed time of the request (approximately)

~/myenv/lib/python3.5/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    447                     decode_content=False,
    448                     retries=self.max_retries,
--> 449                     timeout=timeout
    450                 )
    451 

~/myenv/lib/python3.5/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    598                                                   timeout=timeout_obj,
    599                                                   body=body, headers=headers,
--> 600                                                   chunked=chunked)
    601 
    602             # If we're going to release the connection in ``finally:``, then

~/myenv/lib/python3.5/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    352             conn.request_chunked(method, url, **httplib_request_kw)
    353         else:
--> 354             conn.request(method, url, **httplib_request_kw)
    355 
    356         # Reset the timeout for the recv() on the socket

/usr/lib/python3.5/http/client.py in request(self, method, url, body, headers)
   1104     def request(self, method, url, body=None, headers={}):
   1105         """Send a complete request to the server."""
-> 1106         self._send_request(method, url, body, headers)
   1107 
   1108     def _set_content_length(self, body, method):

/usr/lib/python3.5/http/client.py in _send_request(self, method, url, body, headers)
   1149             # default charset of iso-8859-1.
   1150             body = _encode(body, 'body')
-> 1151         self.endheaders(body)
   1152 
   1153     def getresponse(self):

/usr/lib/python3.5/http/client.py in endheaders(self, message_body)
   1100         else:
   1101             raise CannotSendHeader()
-> 1102         self._send_output(message_body)
   1103 
   1104     def request(self, method, url, body=None, headers={}):

/usr/lib/python3.5/http/client.py in _send_output(self, message_body)
    934         self.send(msg)
    935         if message_body is not None:
--> 936             self.send(message_body)
    937 
    938     def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):

/usr/lib/python3.5/http/client.py in send(self, data)
    906             return
    907         try:
--> 908             self.sock.sendall(data)
    909         except TypeError:
    910             if isinstance(data, collections.Iterable):

/usr/lib/python3.5/ssl.py in sendall(self, data, flags)
    889             count = 0
    890             while (count < amount):
--> 891                 v = self.send(data[count:])
    892                 count += v
    893             return amount

/usr/lib/python3.5/ssl.py in send(self, data, flags)
    859                     "non-zero flags not allowed in calls to send() on %s" %
    860                     self.__class__)
--> 861             return self._sslobj.write(data)
    862         else:
    863             return socket.send(self, data, flags)

/usr/lib/python3.5/ssl.py in write(self, data)
    584         The 'data' argument must support the buffer interface.
    585         """
--> 586         return self._sslobj.write(data)
    587 
    588     def getpeercert(self, binary_form=False):

OverflowError: string longer than 2147483647 bytes

`all_versions=True` doesn't actually list all versions of an analytic

In [1]: from voxel51.users.api import API                                       

In [2]: api = API()                                                             

In [3]: analytics = api.list_analytics()                                        

In [4]: len(analytics)                                                          
Out[4]: 35

In [5]: [a for a in analytics if a["name"] == "voxel51/road-sense"]             
Out[5]: 
[{'scope': 'public',
  'id': 'ae1e82f5-23a8-456a-914c-dadd789bc6a4',
  'name': 'voxel51/road-sense',
  'version': '0.7.1'}]

In [6]: analytics = api.list_analytics(all_versions=True)                       

In [7]: len(analytics)                                                          
Out[7]: 35

In [8]: [a for a in analytics if a["name"] == "voxel51/road-sense"]             
Out[8]: 
[{'scope': 'public',
  'id': 'ae1e82f5-23a8-456a-914c-dadd789bc6a4',
  'name': 'voxel51/road-sense',
  'version': '0.7.1'}]

Screen Shot 2019-11-27 at 11 36 42 PM

TypeError when running `upload_analytic` method

from voxel51.api import API
api = API()
api.upload_analytic("/path/to/analytic.json")

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-1f6d68783277> in <module>
----> 1 api.upload_analytic("/path/to/analytic.json")

~/api-py/voxel51/api.py in upload_analytic(self, doc_json_path)
    168             res = self._requests.post(
    169                 endpoint, headers=self._header, files=files)
--> 170         _validate_response(res)
    171         return _parse_json_response(res)["analytic"]
    172 

~/api-py/voxel51/api.py in _validate_response(res)
    793 def _validate_response(res):
    794     if not res.ok:
--> 795         raise APIError.from_response(res)
    796 
    797 

~/api-py/voxel51/api.py in from_response(cls, res)
    780 
    781         try:
--> 782             message = _parse_json_response(res)["error"]["message"]
    783         except ValueError:
    784             res.raise_for_status()

~/api-py/voxel51/api.py in _parse_json_response(res)
    797 
    798 def _parse_json_response(res):
--> 799     return json.loads(res.content)

/usr/lib/python3.5/json/__init__.py in loads(s, encoding, cls, object_hook, pars
e_float, parse_int, parse_constant, object_pairs_hook, **kw)
    310     if not isinstance(s, str):
    311         raise TypeError('the JSON object must be str, not {!r}'.format(
--> 312                             s.__class__.__name__))
    313     if s.startswith(u'\ufeff'):
    314         raise JSONDecodeError("Unexpected UTF-8 BOM (decode using utf-8-
sig)",

TypeError: the JSON object must be str, not 'bytes'

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.