Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing berth_calls.models results in TypeError: list indices must be integers or slices, not str #64

Open
1kastner opened this issue Apr 13, 2022 · 1 comment

Comments

@1kastner
Copy link

I issued a request as described in https://github.com/amphinicy/marine-traffic-client-api#ev03-berth-calls

Then, I tried to to access the models with berth_calls.models but this resulted in a TypeError, i.e.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [22], in <cell line: 1>()
----> 1 berth_calls.models

File ~\Anaconda3\lib\site-packages\marinetrafficapi\response.py:52, in Response.models(self)
     49 if not self._response_data[ClientConst.MODELS]:
     50     formatted_data = self.formatter.format(self._data)
     51     self._response_data[ClientConst.MODELS] = \
---> 52         self._model.process(
     53             self.formatter.to_list(formatted_data))
     55 return self._response_data[ClientConst.MODELS]

File ~\Anaconda3\lib\site-packages\marinetrafficapi\models.py:38, in Model.process(cls, data)
     32 # check if the model property
     33 # is an instance of Field class
     34 if isinstance(property_object, Field):
     35 
     36     # convert raw property data into corespondent
     37     # data type defined by the Field class
---> 38     property_object.convert_item(model_object)
     40     # set model property value with formatted data
     41     setattr(model_object, model_property,
     42             deepcopy(property_object))

File ~\Anaconda3\lib\site-packages\marinetrafficapi\fields.py:22, in Field.convert_item(self, model)
     19 """Convert item to desired item type"""
     21 try:
---> 22     self.value = model.item[self._index]
     23 except IndexError:
     24     self.value = None

TypeError: list indices must be integers or slices, not str
@1kastner
Copy link
Author

My hypothesis is that because I chose json as the returned structure and it automatically chose an array/list representation, things got messed up. Maybe I must keep it as xml or choose jsono? The list version is irritating anyways as I can only guess which entry means what...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant