liftoff / pyminifier

Pyminifier is a Python code minifier, obfuscator, and compressor.
GNU General Public License v3.0
1.46k stars 223 forks source link

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

Open sunapi386 opened 6 years ago

sunapi386 commented 6 years ago

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 commented 6 years ago
(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> 
xvolte commented 6 years ago

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?

lwhowe commented 6 years ago

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.

xvolte commented 6 years ago

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 commented 6 years ago

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)

lwhowe commented 6 years ago

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