vandersat / vds-api-client

API client for the VanderSat API
MIT License
3 stars 18 forks source link

TypeError: tuple indices must be integers or slices, not str #18

Closed sshoaie closed 4 years ago

sshoaie commented 4 years ago

The script

from vds_api_client import VdsApiV2

vds = VdsApiV2('sshoaie@vandersat.com', password)

See here that a random ROI is found:

vds.rois.filter(name_regex='TestAx')
 # ID # |                                              # Name #                                              |   # Area #   |       # Description #     
==========================================================================================================================================================
  16133 | TestAxAClimateDemo_VdS_AxAClimate_Germany_Baden-Württemberg_Heilbronn_Bad Friedrichshall_Offenau | 5.775e+02 ha | None

now if I want to remove this through

vds.delete_rois_from_account(vds.rois.filter(name_regex='TestAx'))

it will results in

Traceback (most recent call last):
  File "/usr/share/pycharm/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/home/soroshshoaie/PycharmProjects/vds-api-client/vds_api_client/vds_api_base.py", line 376, in delete_rois_from_account
    self.delete(uri)
  File "/home/soroshshoaie/PycharmProjects/vds-api-client/vds_api_client/requester.py", line 119, in delete
    auth=self.auth['user'],
TypeError: tuple indices must be integers or slices, not str

What will resolve the issue is by changing the following:

    def delete(self, uri, **kwargs):
        r = requests.delete(uri, verify=True,
                            auth=self.auth['user'],
                            headers=vac.HEADERS,
                            **kwargs)
        r.raise_for_status()

into

    def delete(self, uri, **kwargs):
        r = requests.delete(uri, verify=True,
                            auth=self.auth[0],
                            headers=vac.HEADERS,
                            **kwargs)
        r.raise_for_status()

However, when the code is ran again the following issue results in the requests.models.py script:

Connected to pydev debugger (build 201.8743.11)
2020/09/11 02:24:09 - vds_api -     INFO - __init__ @ thr 140552890726208  -  ================== VDS_API initialized ==================
Traceback (most recent call last):
  File "/home/soroshshoaie/miniconda3/envs/api37/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/home/soroshshoaie/miniconda3/envs/api37/lib/python3.8/site-packages/requests/sessions.py", line 516, in request
    prep = self.prepare_request(req)
  File "/home/soroshshoaie/miniconda3/envs/api37/lib/python3.8/site-packages/requests/sessions.py", line 449, in prepare_request
    p.prepare(
  File "/home/soroshshoaie/miniconda3/envs/api37/lib/python3.8/site-packages/requests/models.py", line 318, in prepare
    self.prepare_auth(auth, url)
  File "/home/soroshshoaie/miniconda3/envs/api37/lib/python3.8/site-packages/requests/models.py", line 549, in prepare_auth
    r = auth(self)
TypeError: 'str' object is not callable

because the variable auth is no longer a <class 'requests.auth.HTTPBasicAuth'> but simply sshoaie@vandersat.com.

Any idea on how to resolve the first TypeError?

teije01 commented 4 years ago

I recommend you using environment variables for credentials. much easier. I think I see the problem.

In the code there is a bug:

auth=self.auth['user']

should be

auth=self.auth
sshoaie commented 4 years ago

I just tested this and indeed, it should be self.auth.

Thanks a lot.

teije01 commented 4 years ago

Could you merge that back to master?