I'm running the following code in python 2.7 in Windows 7 and am getting an error:
import arrow
timeNow = arrow.utcnow()
print timeNow
timePST = timeNow.to('US/Pacific')
timeMST = timeNow.to('US/Mountain')
ERROR:
Traceback (most recent call last):
File "C:\Users\flann\Dropbox\Personal\GoogleTrendsFutures\pythonCode\testBug.py", line 5, in <module>
timePST = timeNow.to('US/Pacific')
File "C:\Python27\lib\site-packages\arrow\arrow.py", line 456, in to
tz = parser.TzinfoParser.parse(tz)
File "C:\Python27\lib\site-packages\arrow\parser.py", line 295, in parse
tzinfo = tz.gettz(string)
File "C:\Python27\lib\site-packages\dateutil\tz.py", line 963, in gettz
tz = tzwin(name)
File "C:\Python27\lib\site-packages\dateutil\tzwin.py", line 84, in __init__
tzkey = winreg.OpenKey(handle, "%s\%s" % (TZKEYNAME, name))
WindowsError: [Error 2] The system cannot find the file specified
What is strange is that the code is working perfectly on my other windows machine. I have a feeling that the error is an malconfigured time zone registry, but I've tried: http://support.microsoft.com/KB/2863058 This never returns
Any help would be much appreciated!
tzwin.py throws an error if the string you pass in doesn't correspond to a Windows registry key. To see the valid strings, paste this into a command shell:
reg.exe query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones"
I bet if you run it on both your machines, you'll see there's a "US/Pacific" on the one that works, and a "Pacific Standard Time" on the one that fails. Try this:
timePST = timeNow.to('Pacific Standard Time')