Pytz error: unpack requires a string argument of length 44
tjreedy at udel.edu
Wed Jun 13 23:43:46 CEST 2012
On 6/13/2012 4:55 PM, bringa at gmail.com wrote:
> I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I don't have root on the system I'll be running my script on, so I need to go for a local installation. I copied pytz into a folder in my sys.path and am importing from there. That part seems to work. I downloaded the tarball on http://pypi.python.org/pypi/pytz/#downloads
> So now I'm walking through the examples on http://pytz.sourceforge.net/#example-usage. This is what happens:
> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from datetime import datetime, timedelta
>>>> from pytz import timezone
>>>> import pytz
>>>> utc = pytz.utc
>>>> eastern = timezone('US/Eastern')
> Traceback (most recent call last):
> File "<console>", line 1, in<module>
> File "C:\code\SoF\serversonfire\pytz\__init__.py", line 181, in timezone
> _tzinfo_cache[zone] = build_tzinfo(zone, fp)
> File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_tzinfo
> typecnt, charcnt) = unpack(head_fmt, fp.read(head_size))
> error: unpack requires a string argument of length 44
> Can anyone explain to me why that call fails?
1. Either pytz has a bug, it was not installed correctly, or it does not
work on windows.
2. If you read the module struct section of the fine manual, which you
can easily find by typing 'unpack' on the Index tab of the Windows help
version of the manual, it will tell you the following. Unpack takes two
arguments, a format defining character fields of specifics lengths and a
string whose length must be the sum of those lengths. (The contents of
each field must also match the format spec, but you never got that far.)
If there is a length mismatch, you get the message above.
3. In the specific case, we may presume that head_size is the sum of
field lengths for head_fmt. (You could check; if not, that is a bug.)
Since fp.read cannot read too many bytes, it must have read too little.
("Read up to n bytes from the object and return them.")
You could look in
and see what file fp is supposed to be and then take a look at the file.
Is it empty? Is anything read before the statement that failer?
Terry Jan Reedy
More information about the Python-list