pyminifier icon indicating copy to clipboard operation
pyminifier copied to clipboard

Version 2.2: TypeError: coercing to Unicode: need string or buffer, list found

Open sunapi386 opened this issue 7 years ago • 6 comments

Using the provided tumult.py in example code.

$ pip install git+git://github.com/liftoff/pyminifier.git@master
$ pyminifier --obfuscate --pyz=tumult.pyz tumult.py
Traceback (most recent call last):
  File "/home/jsun/venv/bin/pyminifier", line 11, in <module>
    load_entry_point('pyminifier==2.2', 'console_scripts', 'pyminifier')()
  File "/home/jsun/venv/local/lib/python2.7/site-packages/pyminifier/__main__.py", line 171, in main
    pyminify(options, files)
  File "/home/jsun/venv/local/lib/python2.7/site-packages/pyminifier/__init__.py", line 179, in pyminify
    compression.zip_pack(files, options)
  File "/home/jsun/venv/local/lib/python2.7/site-packages/pyminifier/compression.py", line 177, in zip_pack
    cumulative_size += os.path.getsize(filepath)
  File "/home/jsun/venv/lib/python2.7/genericpath.py", line 57, in getsize
    return os.stat(filename).st_size
TypeError: coercing to Unicode: need string or buffer, list found

Master @ 087ea7b

sunapi386 avatar Oct 25 '17 01:10 sunapi386

(venv) ~/w/minifer> pip --version
pip 9.0.1 from /home/jsun/venv/local/lib/python2.7/site-packages (python 2.7)
(venv) ~/w/minifer> python --version
Python 2.7.12
(venv) ~/w/minifer> virtualenv --version
15.1.0
 ~> virtualenv pyminifier-venv
New python executable in /home/jsun/pyminifier-venv/bin/python
Installing setuptools, pip, wheel...done.
 ~> source ~/pyminifier-venv/bin/activate.fish 
(pyminifier-venv) jsun@autoxdl-027 ~> pip install git+git://github.com/liftoff/pyminifier.git@master
Collecting git+git://github.com/liftoff/pyminifier.git@master
  Cloning git://github.com/liftoff/pyminifier.git (to master) to /tmp/pip-RckwiG-build
Installing collected packages: pyminifier
  Running setup.py install for pyminifier ... done
Successfully installed pyminifier-2.2
(pyminifier-venv) ~> cd workspace/minifer/
(pyminifier-venv) ~/w/minifer> pyminifier --obfuscate --pyz=tumult.pyz tumult.py
Traceback (most recent call last):
  File "/home/jsun/pyminifier-venv/bin/pyminifier", line 11, in <module>
    load_entry_point('pyminifier==2.2', 'console_scripts', 'pyminifier')()
  File "/home/jsun/pyminifier-venv/local/lib/python2.7/site-packages/pyminifier/__main__.py", line 171, in main
    pyminify(options, files)
  File "/home/jsun/pyminifier-venv/local/lib/python2.7/site-packages/pyminifier/__init__.py", line 179, in pyminify
    compression.zip_pack(files, options)
  File "/home/jsun/pyminifier-venv/local/lib/python2.7/site-packages/pyminifier/compression.py", line 177, in zip_pack
    cumulative_size += os.path.getsize(filepath)
  File "/home/jsun/pyminifier-venv/lib/python2.7/genericpath.py", line 57, in getsize
    return os.stat(filename).st_size
TypeError: coercing to Unicode: need string or buffer, list found
(pyminifier-venv)  ~/w/minifer [1]> pip freeze
pyminifier==2.2
(pyminifier-venv)  ~/w/minifer> 

sunapi386 avatar Oct 25 '17 02:10 sunapi386

I got exactly the same error.

It works good without the --pyz option, but as soon as i put the --pyz option, i got the same bug.

Did you manage to correct the issue?

xvolte avatar Jun 13 '18 23:06 xvolte

Hi sunapi386, xvolte, You can fix the problem by edit the call to "compression.zip_pack(files, options)" in _init_.py to "compression.zip_pack(files[0], options)" since it was expecting one python file anyway. files variable was a list or tuple but zip_pack() function "cumulative_size += os.path.getsize(filepath)" expect a string. Cheers.

lwhowe avatar Aug 02 '18 12:08 lwhowe

Hello @lwhowe

Thanks for your help. Unfortunately, the package is installed through pip installer,

do you know how i can make the changes ?

thanks in advance,

xvolte avatar Aug 16 '18 14:08 xvolte

Hello,

i managed to change it here : notepad c:\python27\lib\site-packages\pyminifier\__init__.py but now i have a new problem: IOError: [Errno 13] Permission denied: 'c:\\users\\xavier\\appdata\\local\\temp\\tmptdced0'

But i opened the shell as admin, same error! (the folder does not exists)

xvolte avatar Aug 16 '18 14:08 xvolte

hi @xvolte, guess you are using the pyz option. It works for me in Linux but same problem with yours in Windows.

lwhowe avatar Aug 17 '18 08:08 lwhowe