-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
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
Python Scripts : strptime no longer works #132469
Comments
I think you might need to import datetime first instead of using directly. |
Thank you for the response. In 2024.11.x in 2024.12.0 if I try What has changed and what am I missing? |
Also this issue with integration:Python Scripts not pyscript? |
Nothing changed in the source code and it should work like you had it before so no idea right now actually. |
Further thoughts:- |
On the off chance anybody else might be experiencing an issue with strptime I have found that:- |
In case it helps anyone: I ran into a very similar issue with This issue helped me identify the problematic call and try alternatives, so thank you! (The specific error I was experiencing was |
I have also run to the same issue. I’m using python_script heavily and several logics rely on strptime function. So I’m looking forward to the resolution. |
I have the same issue since 2024.12. can not use datetime.datetime.strptime anymore. Thanks to @MisterRadish, I got a workaround working based on datetime.datetime.fromisoformat |
So I gave this a test now on both bookingdate = datetime.datetime.strptime("2024-04-01", "%Y-%m-%d")
logger.info(f"Date {bookingdate}") Output:
On dev we are still on py3.12 so I wonder if there is something that has changed here between the python versions that might have an impact. |
Yup - the move to python 3.13 in 2024.12.0 could be the cause |
I can at least at this stage confirm that py3.13 is the cause of the issue |
A fix has been released in 2024.12.4. Thank you for your help @gjohansson-ST |
The problem
Converting string to datetime using strptime now produces error
Error executing script (KeyError): '__import__' when running the script.)
example:
bookingdate = datetime.datetime.strptime("2024-04-01", "%Y-%m-%d")
What version of Home Assistant Core has the issue?
2024.12.0
2024.12.1
2024.12.2
What was the last working version of Home Assistant Core?
2024.11.x
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Python Scripts
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: