f



Pytz error: unpack requires a string argument of length 44

Hi!

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 impo=
rting 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/#exa=
mple-usage. This is what happens:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] o=
n win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from datetime import datetime, timedelta
>>> from pytz import timezone
>>> import pytz
>>> utc =3D pytz.utc
>>> utc.zone
'UTC'
>>> eastern =3D 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] =3D build_tzinfo(zone, fp)
  File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_tzinfo
    typecnt, charcnt) =3D  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?
0
bringa1 (8)
6/13/2012 8:55:06 PM
comp.lang.python 77058 articles. 6 followers. Post Follow

7 Replies
2021 Views

Similar Articles

[PageSpeed] 45

On 6/13/2012 4:55 PM, bringa@gmail.com wrote:
> Hi!
>
> 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.
> (InteractiveConsole)
>>>> from datetime import datetime, timedelta
>>>> from pytz import timezone
>>>> import pytz
>>>> utc = pytz.utc
>>>> utc.zone
> '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
C:\code\SoF\serversonfire\pytz\__init__.py
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

0
tjreedy (5460)
6/13/2012 9:43:46 PM
Thanks Terry!=20

There indeed seems to be something wrong with my installation of pytz. I ha=
d a look around the zoneinfo dir, which is where build_tzinfo polls its inf=
o from, and a whole bunch of files are 0 bytes. Whenever I try to instantia=
te a timezone whose corresponding file is 0 bytes I get that error (it's tr=
ying to read the head of the tzinfo file to make sure the right magic bytes=
 are in there, and reading 44 bytes out of a 0 byte file isn't going to wor=
k).

So I guess I'll poke around to find some specific help with pytz or a non-b=
roken zoneinfo dir.

On Wednesday, June 13, 2012 10:43:46 PM UTC+1, Terry Reedy wrote:
> On 6/13/2012 4:55 PM, I wrote:
> > Hi!
> >
> > I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I do=
n't have root on the system I'll be running my script on, so I need to go f=
or 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.
> > (InteractiveConsole)
> >>>> from datetime import datetime, timedelta
> >>>> from pytz import timezone
> >>>> import pytz
> >>>> utc =3D pytz.utc
> >>>> utc.zone
> > 'UTC'
> >>>> eastern =3D 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 time=
zone
> >      _tzinfo_cache[zone] =3D build_tzinfo(zone, fp)
> >    File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_t=
zinfo
> >      typecnt, charcnt) =3D  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?
>=20
> 1. Either pytz has a bug, it was not installed correctly, or it does not=
=20
> work on windows.
>=20
> 2. If you read the module struct section of the fine manual, which you=20
> can easily find by typing 'unpack' on the Index tab of the Windows help=
=20
> version of the manual, it will tell you the following. Unpack takes two=
=20
> arguments, a format defining character fields of specifics lengths and a=
=20
> string whose length must be the sum of those lengths. (The contents of=20
> each field must also match the format spec, but you never got that far.)=
=20
> If there is a length mismatch, you get the message above.
>=20
> 3. In the specific case, we may presume that head_size is the sum of=20
> field lengths for head_fmt. (You could check; if not, that is a bug.)=20
> Since fp.read cannot read too many bytes, it must have read too little.=
=20
> ("Read up to n bytes from the object and return them.")
>=20
> You could look in
> C:\code\SoF\serversonfire\pytz\__init__.py
> and see what file fp is supposed to be and then take a look at the file.=
=20
> Is it empty? Is anything read before the statement that failer?
>=20
> --=20
> Terry Jan Reedy

0
bringa1 (8)
6/13/2012 9:59:02 PM
Thanks Terry!=20

There indeed seems to be something wrong with my installation of pytz. I ha=
d a look around the zoneinfo dir, which is where build_tzinfo polls its inf=
o from, and a whole bunch of files are 0 bytes. Whenever I try to instantia=
te a timezone whose corresponding file is 0 bytes I get that error (it's tr=
ying to read the head of the tzinfo file to make sure the right magic bytes=
 are in there, and reading 44 bytes out of a 0 byte file isn't going to wor=
k).

So I guess I'll poke around to find some specific help with pytz or a non-b=
roken zoneinfo dir.

On Wednesday, June 13, 2012 10:43:46 PM UTC+1, Terry Reedy wrote:
> On 6/13/2012 4:55 PM, I wrote:
> > Hi!
> >
> > I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I do=
n't have root on the system I'll be running my script on, so I need to go f=
or 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.
> > (InteractiveConsole)
> >>>> from datetime import datetime, timedelta
> >>>> from pytz import timezone
> >>>> import pytz
> >>>> utc =3D pytz.utc
> >>>> utc.zone
> > 'UTC'
> >>>> eastern =3D 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 time=
zone
> >      _tzinfo_cache[zone] =3D build_tzinfo(zone, fp)
> >    File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_t=
zinfo
> >      typecnt, charcnt) =3D  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?
>=20
> 1. Either pytz has a bug, it was not installed correctly, or it does not=
=20
> work on windows.
>=20
> 2. If you read the module struct section of the fine manual, which you=20
> can easily find by typing 'unpack' on the Index tab of the Windows help=
=20
> version of the manual, it will tell you the following. Unpack takes two=
=20
> arguments, a format defining character fields of specifics lengths and a=
=20
> string whose length must be the sum of those lengths. (The contents of=20
> each field must also match the format spec, but you never got that far.)=
=20
> If there is a length mismatch, you get the message above.
>=20
> 3. In the specific case, we may presume that head_size is the sum of=20
> field lengths for head_fmt. (You could check; if not, that is a bug.)=20
> Since fp.read cannot read too many bytes, it must have read too little.=
=20
> ("Read up to n bytes from the object and return them.")
>=20
> You could look in
> C:\code\SoF\serversonfire\pytz\__init__.py
> and see what file fp is supposed to be and then take a look at the file.=
=20
> Is it empty? Is anything read before the statement that failer?
>=20
> --=20
> Terry Jan Reedy

0
bringa1 (8)
6/13/2012 9:59:02 PM
> There indeed seems to be something wrong with my installation of pytz=2E =
I had a=0D=0A> look around the zoneinfo dir, which is where build_tzinfo po=
lls its info from,=0D=0A> and a whole bunch of files are 0 bytes=2E Wheneve=
r I try to instantiate a=0D=0A> timezone whose corresponding file is 0 byte=
s I get that error (it's trying to=0D=0A> read the head of the tzinfo file =
to make sure the right magic bytes are in=0D=0A> there, and reading 44 byte=
s out of a 0 byte file isn't going to work)=2E=0D=0A> =0D=0A> So I guess I'=
ll poke around to find some specific help with pytz or a non-=0D=0A> broken=
 zoneinfo dir=2E=0D=0A=0D=0ADid you follow the installation instructions lo=
cated on the front page?=0D=0A=0D=0AI would unpack the tarball (not in a Py=
thon directory) and then do =0D=0A`python setup=2Epy install` (use the full=
 path to the executable you want=0D=0Athe module installed to if you have m=
ore than one version of Python installed)=0D=0Afrom the directory with the =
unpacked contents of the tarball=2E I did not need =0D=0Aadmin rights to ma=
nually install on Windows, but that might depend on =0D=0Awhere your Python=
 is installed=2E=0D=0A=0D=0ARamit=0D=0A=0D=0A=0D=0ARamit Prasad | JPMorgan =
Chase Investment Bank | Currencies Technology=0D=0A712 Main Street | Housto=
n, TX 77002=0D=0Awork phone: 713 - 216 - 5423=0D=0A=0D=0A--=0D=0AThis email=
 is confidential and subject to important disclaimers and=0D=0Aconditions i=
ncluding on offers for the purchase or sale of=0D=0Asecurities, accuracy an=
d completeness of information, viruses,=0D=0Aconfidentiality, legal privile=
ge, and legal entity disclaimers,=0D=0Aavailable at http://www=2Ejpmorgan=
=2Ecom/pages/disclosures/email=2E  
0
6/13/2012 10:25:28 PM
The windows box is my development box, it's not where the script will be running in the end. It'll be running on a Linux box where I don't have root so python setup.py install isn't an option (to my understanding).

So what happened is that 7zip didn't unzip the .tar.gz2 properly, but it does fine with the .zip from the Python Package Index. Using the zoneinfo from the properly unzipped file everything works.

Thanks everyone, consider this solved.

On Wednesday, June 13, 2012 11:25:28 PM UTC+1, Prasad, Ramit wrote:
> > There indeed seems to be something wrong with my installation of pytz. I had a
> > look around the zoneinfo dir, which is where build_tzinfo polls its info from,
> > and a whole bunch of files are 0 bytes. Whenever I try to instantiate a
> > timezone whose corresponding file is 0 bytes I get that error (it's trying to
> > read the head of the tzinfo file to make sure the right magic bytes are in
> > there, and reading 44 bytes out of a 0 byte file isn't going to work).
> > 
> > So I guess I'll poke around to find some specific help with pytz or a non-
> > broken zoneinfo dir.
> 
> Did you follow the installation instructions located on the front page?
> 
> I would unpack the tarball (not in a Python directory) and then do 
> `python setup.py install` (use the full path to the executable you want
> the module installed to if you have more than one version of Python installed)
> from the directory with the unpacked contents of the tarball. I did not need 
> admin rights to manually install on Windows, but that might depend on 
> where your Python is installed.
> 
> Ramit
> 
> 
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
> 
> --
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.

0
bringa1 (8)
6/14/2012 1:05:12 AM
The windows box is my development box, it's not where the script will be running in the end. It'll be running on a Linux box where I don't have root so python setup.py install isn't an option (to my understanding).

So what happened is that 7zip didn't unzip the .tar.gz2 properly, but it does fine with the .zip from the Python Package Index. Using the zoneinfo from the properly unzipped file everything works.

Thanks everyone, consider this solved.

On Wednesday, June 13, 2012 11:25:28 PM UTC+1, Prasad, Ramit wrote:
> > There indeed seems to be something wrong with my installation of pytz. I had a
> > look around the zoneinfo dir, which is where build_tzinfo polls its info from,
> > and a whole bunch of files are 0 bytes. Whenever I try to instantiate a
> > timezone whose corresponding file is 0 bytes I get that error (it's trying to
> > read the head of the tzinfo file to make sure the right magic bytes are in
> > there, and reading 44 bytes out of a 0 byte file isn't going to work).
> > 
> > So I guess I'll poke around to find some specific help with pytz or a non-
> > broken zoneinfo dir.
> 
> Did you follow the installation instructions located on the front page?
> 
> I would unpack the tarball (not in a Python directory) and then do 
> `python setup.py install` (use the full path to the executable you want
> the module installed to if you have more than one version of Python installed)
> from the directory with the unpacked contents of the tarball. I did not need 
> admin rights to manually install on Windows, but that might depend on 
> where your Python is installed.
> 
> Ramit
> 
> 
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
> 
> --
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.

0
bringa1 (8)
6/14/2012 1:05:12 AM
On Thu, Jun 14, 2012 at 6:35 AM, Daniel Klein <bringa@gmail.com> wrote:
> The windows box is my development box, it's not where the script will be running in the end. It'll be running on a Linux box where I don't have root so python setup.py install isn't an option (to my understanding).
>

You might want to use virtualenv for this:
http://pypi.python.org/pypi/virtualenv

> So what happened is that 7zip didn't unzip the .tar.gz2 properly, but it does fine with the .zip from the Python Package Index. Using the zoneinfo from the properly unzipped file everything works.
>

-- 
regards,
kushal
0
python2058 (95)
6/14/2012 6:39:09 AM
Reply: