Skip to content

get_consumption_data name of input distrubutor_code and formats #10

@antviro

Description

@antviro

Hi Mr Marble!

First of all thank you for developing this tool to manage datadis api from python.

I have been playing around a bit and I got trapped into get_consumption_data:

I see distributor_code is named here distrubutor_code which I guess is just a typo.

In the other parameters I am getting errors and I have not a clear idea of how to sort them out. I think the errors are related with the integer to string conversion of several parameters. Do you have an example of successful access to get_consumption_data ?

I follow types described in get_consumption_data, but I also tried ignoring it and following the ones described in the API (all strings):


consumption_data = asyncio.run(dd.get_consumption_data(token=token, cups=cups, start_date="2023/01/01", end_date="2023/31/01", measurement_type=1, point_type=2,distrubutor_code=8, authorized_nif=cif))


File /usr/lib/python3.11/asyncio/runners.py:190, in run(main, debug)
    186     raise RuntimeError(
    187         "asyncio.run() cannot be called from a running event loop")
    189 with Runner(debug=debug) as runner:
--> 190     return runner.run(main)

File /usr/lib/python3.11/asyncio/runners.py:118, in Runner.run(self, coro, context)
    116 self._interrupt_count = 0
    117 try:
--> 118     return self._loop.run_until_complete(task)
    119 except exceptions.CancelledError:
    120     if self._interrupt_count > 0:

File /usr/lib/python3.11/asyncio/base_events.py:653, in BaseEventLoop.run_until_complete(self, future)
    650 if not future.done():
    651     raise RuntimeError('Event loop stopped before Future completed.')
--> 653 return future.result()

File ~/virtual_environments_python/elpower/lib/python3.11/site-packages/datadis/__init__.py:129, in get_consumption_data(token, cups, distrubutor_code, start_date, end_date, measurement_type, point_type, authorized_nif)
    127 if authorized_nif:
    128     params["authorizedNif"] = authorized_nif
--> 129 return await _request(
    130     _ENDPOINTS["get_consumption_data"], token, params, ConsumptionData
    131 )

File ~/virtual_environments_python/elpower/lib/python3.11/site-packages/datadis/__init__.py:184, in _request(endpoint, token, params, output_type)
    182     return result
    183 else:
--> 184     raise ConnectionError(f'Error: {r.json()["message"]}')

File ~/virtual_environments_python/elpower/lib/python3.11/site-packages/httpx/_models.py:756, in Response.json(self, **kwargs)
    754     if encoding is not None:
    755         return jsonlib.loads(self.content.decode(encoding), **kwargs)
--> 756 return jsonlib.loads(self.text, **kwargs)

File /usr/lib/python3.11/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    341     s = s.decode(detect_encoding(s), 'surrogatepass')
    343 if (cls is None and object_hook is None and
    344         parse_int is None and parse_float is None and
    345         parse_constant is None and object_pairs_hook is None and not kw):
--> 346     return _default_decoder.decode(s)
    347 if cls is None:
    348     cls = JSONDecoder

File /usr/lib/python3.11/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
    332 def decode(self, s, _w=WHITESPACE.match):
    333     """Return the Python representation of ``s`` (a ``str`` instance
    334     containing a JSON document).
    335 
    336     """
--> 337     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338     end = _w(s, end).end()
    339     if end != len(s):

File /usr/lib/python3.11/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
    353     obj, end = self.scan_once(s, idx)
    354 except StopIteration as err:
--> 355     raise JSONDecodeError("Expecting value", s, err.value) from None
    356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I saw a closed issue which may be related with this: #8 Although as it was closed I have opened a new one...

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions