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

TypeError while executing 'pybabel update ...' in Python 3.x #91

Closed
williamwu0220 opened this Issue Apr 27, 2014 · 17 comments

Comments

Projects
None yet
@williamwu0220

williamwu0220 commented Apr 27, 2014

I installed babel in Python 3.4.0 env, and babel cannot work while using update sub-command as follows:

william$ pybabel update -i i18n/locale/message.pot  -l zh_TW -d i18n/locale/ -D i18n
updating catalog 'i18n/locale/zh_TW/LC_MESSAGES/i18n.po' based on 'i18n/locale/message.pot'
Traceback (most recent call last):
  File "/Users/william/venv/pyramid/bin/pybabel", line 9, in <module>
    load_entry_point('Babel==1.3', 'console_scripts', 'pybabel')()
  File "/Users/william/venv/pyramid/lib/python3.4/site-packages/babel/messages/frontend.py", line 1151, in main
    return CommandLineInterface().run(sys.argv)
  File "/Users/william/venv/pyramid/lib/python3.4/site-packages/babel/messages/frontend.py", line 665, in run
    return getattr(self, cmdname)(args[1:])
  File "/Users/william/venv/pyramid/lib/python3.4/site-packages/babel/messages/frontend.py", line 1130, in update
    width=options.width)
  File "/Users/william/venv/pyramid/lib/python3.4/site-packages/babel/messages/pofile.py", line 444, in write_po
    _write(comment_header + u'\n')
  File "/Users/william/venv/pyramid/lib/python3.4/site-packages/babel/messages/pofile.py", line 388, in _write
    fileobj.write(text)
TypeError: must be str, not bytes

My env:
python: 3.4.0
os: Debian Wheezy
Babel: 1.3

@AlexKovalevych

This comment has been minimized.

AlexKovalevych commented Aug 24, 2014

+1

1 similar comment
@atomd-zz

This comment has been minimized.

atomd-zz commented Sep 22, 2014

+1

@giampaolo

This comment has been minimized.

giampaolo commented Oct 7, 2014

+1
Our migration is currently blocked by this.

@giampaolo

This comment has been minimized.

giampaolo commented Oct 7, 2014

Here's some more input which I hope it will help debugging this problem.
This is the situation before hitting TypeError:

(Pdb) fileobj
<_io.TextIOWrapper name='locale/de/LC_MESSAGES/tmpgoodscloud.po' mode='w' encoding='UTF-8'>
(Pdb) text
b'# SOME DESCRIPTIVE TITLE.\n# Copyright (C) 2013 ORGANIZATION'
(Pdb) fileobj.write(text)
*** TypeError: must be str, not bytes

The problem is "fileobj" which is a TextIOWrapper() instance and the original "fileobj" is created in frontend.py as a text file (instead of a binary file):

tmpname = os.path.join(os.path.dirname(filename),
                       tempfile.gettempprefix() +
                       os.path.basename(filename))
tmpfile = open(tmpname, 'w')
try:
    try:
        write_po(tmpfile, catalog,
                 ignore_obsolete=self.ignore_obsolete,
                 include_previous=self.previous, width=self.width)
        ...

The code extract above was taken from Babel 1.3, which is currently the latest available version on PYPI. I now took a quick look at latest GIT code on master which looks different:

-    tmpfile = open(tmpname, 'w')
+    tmpfile = open(tmpname, 'wb')

So it seems that this problem has apparently already been fixed. What we need is a new version of Babel officially released on PYPI. Any plans on when that might happen? IMHO this should be considered a high-priority issue.

@williamwu0220

This comment has been minimized.

williamwu0220 commented Oct 7, 2014

+1 again. This is the last issue which is blocking me using Python 3 with Pyramid. :(

@jayesh-bhoot

This comment has been minimized.

jayesh-bhoot commented Oct 16, 2014

Agreed. And officially fixed version would be a welcome.

@dmitrybelyakov

This comment has been minimized.

dmitrybelyakov commented Nov 15, 2014

Same for us

@rosariomgomez

This comment has been minimized.

rosariomgomez commented Nov 19, 2014

+1 here..., any update on when the new package will be released on pypi? thank you very much for your work

@andras-tim

This comment has been minimized.

andras-tim commented Dec 16, 2014

+1

@williamwu0220

This comment has been minimized.

williamwu0220 commented Feb 17, 2015

Looks like this issue had been solved in master branch. Will there be any release plan in the near future? Or should we need to fork this project to make that happen? Please... :(

@torotil

This comment has been minimized.

torotil commented Mar 23, 2015

+1

@williamwu0220

This comment has been minimized.

williamwu0220 commented Apr 14, 2015

I created a new project Py3Babel forked from Babel: https://github.com/williamwu0220/py3babel/
Patches welcome..
You can install the package via pip:
pip install Py3Babel

@alissonperez

This comment has been minimized.

alissonperez commented Apr 27, 2015

+1. Make a release, please!!

@jmagnusson

This comment has been minimized.

jmagnusson commented May 12, 2015

Have you abandoned the project, @mitsuhiko? Or do you just need contributors?

@jmagnusson jmagnusson referenced this issue May 12, 2015

Closed

New release #158

@xmnlab xmnlab referenced this issue Jun 17, 2015

Closed

bug fix #163

@mitsuhiko

This comment has been minimized.

Member

mitsuhiko commented Jul 27, 2015

I need support for maintaining this project badly. If someone is up for helping out with it, please contact me :)

@mitsuhiko

This comment has been minimized.

Member

mitsuhiko commented Jul 27, 2015

This particular issue should be fixed however.

@mitsuhiko mitsuhiko closed this Jul 27, 2015

@jmagnusson

This comment has been minimized.

jmagnusson commented Jul 27, 2015

Great news! I don't really know my way around the code of this project so I'll have to pass. Hope you find that special someone.

jaywink added a commit to jaywink/shoop that referenced this issue Aug 3, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Aug 3, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Aug 3, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Aug 3, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Sep 20, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Sep 20, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Sep 20, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Sep 20, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Sep 25, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Oct 2, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

jaywink added a commit to jaywink/shoop that referenced this issue Nov 6, 2015

Start translating Shoop to Finnish
Init locale dir. Include compiled .mo files, for now. Add to manifest.
Bump Babel to 2.0 due to 3.4 Python compatibility, see bug:
python-babel/babel#91

matt9j added a commit to uw-ictd/CommunityCellularManager that referenced this issue Jun 8, 2018

[client] Update Babel to latest to support python 3
Running packaging was hitting this known issue
python-babel/babel#91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment