8000 TypeError: Struct() argument 1 must be string, not unicode · Issue #993 · fonttools/fonttools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

TypeError: Struct() argument 1 must be string, not unicode #993

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

Closed
banxian opened this issue Jun 25, 2017 · 7 comments
Closed

TypeError: Struct() argument 1 must be string, not unicode #993

banxian opened this issue Jun 25, 2017 · 7 comments

Comments

@banxian
Copy link
banxian commented Jun 25, 2017

I have ttx via pip install fonttools, and use it to convert SourceHanSans.
but it give me an exception like this:

Dumping "SourceHanSansCN-Normal.otf" to "SourceHanSansCN-Normal.ttx"...
Dumping 'GlyphOrder' table...
Dumping 'head' table...
Dumping 'hhea' table...
Dumping 'maxp' table...
Dumping 'OS/2' table...
ERROR: Unhandled exception has occurred
Traceback (most recent call last):
File "f:\python27\lib\site-packages\fontTools\ttx.py", line 387, in main
process(jobs, options)
File "f:\python27\lib\site-packages\fontTools\ttx.py", line 361, in process
action(input, output, options)
File "f:\python27\lib\site-packages\fontTools\misc\loggingTools.py", line 372, in wrapper
return func(*args, **kwds)
File "f:\python27\lib\site-packages\fontTools\ttx.py", line 258, in ttDump
newlinestr=options.newlinestr)
File "f:\python27\lib\site-packages\fontTools\ttLib_init_.py", line 311, in saveXML
self.tableToXML(tableWriter, tag, progress)
File "f:\python27\lib\site-packages\fontTools\ttLib_init
.py", line 329, in tableToXML
table = self[tag]
File "f:\python27\lib\site-packages\fontTools\ttLib_init
.py", line 419, in getitem
tableClass = getTableClass(tag)
File "f:\python27\lib\site-packages\fontTools\ttLib_init_.py", line 825, in getTableClass
module = getTableModule(tag)
File "f:\python27\lib\site-packages\fontTools\ttLib_init_.py", line 807, in getTableModule
import("fontTools.ttLib.tables." + pyTag)
File "f:\python27\lib\site-packages\fontTools\ttLib\tables_n_a_m_e.py", line 26, in
nameRecordSize = sstruct.calcsize(nameRecordFormat)
File "f:\python27\lib\site-packages\fontTools\misc\sstruct.py", line 108, in calcsize
return struct.calcsize(formatstring)
TypeError: Struct() argument 1 must be string, not unicode
(Hit any key to exit)

python version is 2.7.3, os is windows 7 x64 sp1.

@behdad
Copy link
Member
behdad commented Jun 25, 2017

Humm. I suspect e853036#diff-31a4f6d5cfe6b730aa7a52f036df840dR3, but why does it not fail in our continuous testing?

@banxian
Copy link
Author
banxian commented Jun 25, 2017

maybe my font (SourceHanSansCN-Normal.otf) have some magic triggered this exception.
it's 1.004 version which got from Adobe's source han project.

@anthrotype
Copy link
Member

Before python 2.7.7 the struct module didn't support unicode strings, but required a nativ str (bytes).
https://bugs.python.org/issue19099

We don't run tests on such old pythons on our CI.
I'd suggest a wontfix and "please update your python, or better use python3".

@behdad
Copy link
Member
behdad commented Jun 25, 2017

sgtm

@vane
Copy link
vane commented Aug 23, 2017

Hi,
I have same problem unfortunately I cannot update python so easily. It doesn't depend on me.
I created pull request that fix this issue.
master...vane:master
I tested it with python 2.7.5
Hope that will help anyone that have same problem.

@anthrotype
Copy link
Member

It turns out some fonttools users are still stuck with pythons older than 2.7.7.

I wouldn't like to add another Travis build to check for such old python, it's slow enough already.
Let's content ourselves of occasionally fixing things based on users' report.. Until the https://pythonclock.org/ finally reaches its end.

@anthrotype
Copy link
Member
anthrotype commented Oct 19, 2017

for this specific issue with the py27 struct module, fonttools devs should remember to explicitly use bytes for the struct.pack and unpack format string (using the b"" notation) whenever the module in which the call to struct appears also imports unicode_literals.
The unicode_literals module is known to have some issue with some stdlib modules, but sometimes the convenience of not prefixing everything with u"" outweighs its downsides.
Let's stick to using it like we currently do, i.e. only when a module manipulates potentially non-ASCII text strings.

anthrotype added a commit that referenced this issue Oct 20, 2017
properly fixes issue with struct module in python < 2.7.7

#993
anthrotype added a commit that referenced this issue Oct 20, 2017
We install python 2.7.6 using pyenv.

This should help us catch issues like this earlier
#993
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3E0E None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0