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

Error with the isoformat string #123

Closed
SW-OS opened this issue Apr 9, 2024 · 8 comments · Fixed by #125
Closed

Error with the isoformat string #123

SW-OS opened this issue Apr 9, 2024 · 8 comments · Fixed by #125
Assignees
Labels
bug Something isn't working

Comments

@SW-OS
Copy link

SW-OS commented Apr 9, 2024

Hello,

I'm using your script successfully.. thanks for your work.

But since version 1.3.10 I got an error concerning the iosformat string.
Reinstallung version 1.3.9 the error was not seen anymore.

I renamed the example.py to connection_org.py and entered the password and account. Subsequently I started the script from the command shell on a raspberry like: python3 connection_org.py and got the following output:

File "connect_org.py", line 358, in
loop.run_until_complete(main())
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "connect_org.py", line 247, in main
print(f'\tstr_state: {instrument.str_state} - state: {instrument.state}')
File "/usr/local/lib/python3.7/dist-packages/skodaconnect/dashboard.py", line 123, in str_state
return f'{self.state}'
File "/usr/local/lib/python3.7/dist-packages/skodaconnect/dashboard.py", line 127, in state
val = super().state
File "/usr/local/lib/python3.7/dist-packages/skodaconnect/dashboard.py", line 58, in state
if hasattr(self.vehicle, self.attr):
File "/usr/local/lib/python3.7/dist-packages/skodaconnect/vehicle.py", line 1542, in last_connected
last_connected = datetime.fromisoformat(last_connected_utc)
ValueError: Invalid isoformat string: '2024-04-09T05:10:13.029Z'

Thanks for any tipps

Stefan

@SW-OS SW-OS added the bug Something isn't working label Apr 9, 2024
@dvx76
Copy link
Member

dvx76 commented Apr 9, 2024

See #109. This happens on Python 3.9 or below. datetime.fromisoformat was apparently changed in Python 3.10 or 3.11. We need to update the requires-python in this pyproject.toml to reflect that.

dvx76 added a commit to dvx76/skodaconnect that referenced this issue Apr 13, 2024
Align with requirements.txt. Required for skodaconnect#109. Note that HA-core
already depends on 3.12.

Fixes skodaconnect#123
@dvx76 dvx76 self-assigned this Apr 13, 2024
@SW-OS
Copy link
Author

SW-OS commented Apr 29, 2024

Hello,

just now, I installed the new 1.3.11 version, but I got the same error as before.

Sorry, but 1.3.11 has still the isostring problem.

Thanks

Stefan

@dvx76
Copy link
Member

dvx76 commented Apr 29, 2024

There is no fix, you just need to update your Python version. #125 just bumps the minimum Python version required for this package to 3.11.

@SW-OS
Copy link
Author

SW-OS commented Apr 30, 2024

Sorry for my misunderstanding...
Unfortunately I cannot influence the Python version because the script runs on a commercial web server. The company won't update Python for a few months.
Isn't there a possibility that the "timezone format" is processed depending on the Python version in your Scripts (i.e. vehicle.py)

Thanks

Stefan

@dvx76
Copy link
Member

dvx76 commented Apr 30, 2024

+ @badrpc FYI if you have any ideas or suggestions

The primary use-case for this project is to be used in Homeassistant, through https://github.com/skodaconnect/homeassistant-skodaconnect so it's going to track the Python versions/requirements from HA, which is currently 3.11 (or even 3.12) I think.

@SW-OS if you can propose a fix which still resolved skodaconnect/homeassistant-skodaconnect#225 / #99 but also works on Python 3.9 that would be ok for me.

@badrpc
Copy link
Contributor

badrpc commented Apr 30, 2024

As I mentioned in #99 (comment) datetime.strptime(last_connected_utc,'%Y-%m-%dT%H:%M:%SZ').astimezone(timezone.utc) can be used instead of datetime.fromisoformat(...). I believe this works in Python 3.9. I don't think it is worth making this conditional on Python version, but probably deserves a comment explaining the problem.

@dvx76
Copy link
Member

dvx76 commented May 1, 2024

@SW-OS are you able to validate if this works for you?

@SW-OS
Copy link
Author

SW-OS commented May 2, 2024

I was following the solution of https://pypi.org/project/backports-datetime-fromisoformat/

This worked perfect without changing your scripts (i.e. vehicle.py) within the module.....

I had only to install the package and to add two lines for importing in the head of the main script....

In my mind the best solution......

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants