joaoricardo000 / whatsapp-bot-seed

A small python framework to create a whatsapp bot, with regex-callback message routing.
727 stars 245 forks source link

Python 3.4: only a few commands working :/ #37

Closed e0xify closed 8 years ago

e0xify commented 8 years ago

if i post an image or want to search something the console just shows me:

_media_sender.py_ [ERROR][2016-01-28 12:23:36,728] Unicode-objects must be encoded before hashing Traceback (most recent call last): File "/home/scripts/wabot/test/whatsapp-bot-seed/src/utils/media_sender.py", line 191, in send file_path = self.tts_record(text, lang) File "/home/scripts/wabot/test/whatsapp-bot-seed/src/utils/media_sender.py", line 198, in tts_record file_path = self._build_file_path(text) File "/home/scripts/wabot/test/whatsapp-bot-seed/src/utils/media_sender.py", line 204, in _build_file_path id = hashlib.md5(text).hexdigest() TypeError: Unicode-objects must be encoded before hashing

joaoricardo000 commented 8 years ago

Hi, that's weird... Can you tell me more about your environment? Python version, OS...

Looks like just this would solve it, but I don't know why are you having this problem in the first place..

_build_file_path id = hashlib.md5(text.encode("UTF-8")).hexdigest()

e0xify commented 8 years ago

Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.3 LTS
Release: 14.04
Codename: trusty

hm okay i will give it a try, but then i have to edit it in all files :/

joaoricardo000 commented 8 years ago

Yeah... probably python 3.4. Right now we are using 2.7. Better if you just use a virtualenv of 2.7 to run the bot...

e0xify commented 8 years ago

hm allright mate, maybe i'll find a way to get python 3.4 replaced with 2.7... thanks ! i'll give feedback

joaoricardo000 commented 8 years ago

Just install 2.7, and create a virtualenv like this: virtualenv -p /usr/bin/python2.7 venv No need to replace or remove 3.4..

e0xify commented 8 years ago

ahh

gimme a second , i think i fu**ed it up. compiled it from source

root@h2476922:/home/Python-2.7.9# python -V
bash: /usr/bin/python3: No such file or directory
root@h2476922:/home/Python-2.7.9# virtualenv -p /usr/bin/python2.7
bash: virtualenv: command not foun

e0xify commented 8 years ago
root@h2476922:/home/scripts/wabot/test/whatsapp-bot-seed# pip install yowsup2                                                                                                                                      
Requirement already satisfied (use --upgrade to upgrade): yowsup2 in /usr/local/lib/python2.7/dist-packages                                                                                                        
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/lib/python2.7/dist-packages (from yowsup2)                                                                                       
Requirement already satisfied (use --upgrade to upgrade): argparse in /usr/lib/python2.7 (from yowsup2)                                                                                                            
Requirement already satisfied (use --upgrade to upgrade): python-axolotl>=0.1.7 in /usr/local/lib/python2.7/dist-packages (from yowsup2)                                                                           
Requirement already satisfied (use --upgrade to upgrade): pillow in /usr/lib/python2.7/dist-packages (from yowsup2)                                                                                                
Requirement already satisfied (use --upgrade to upgrade): protobuf>=2.6,<3.0.0-alpha-2 in /usr/local/lib/python2.7/dist-packages (from python-axolotl>=0.1.7->yowsup2)                                             
Requirement already satisfied (use --upgrade to upgrade): pycrypto in /usr/lib/python2.7/dist-packages (from python-axolotl>=0.1.7->yowsup2)                                                                       
Requirement already satisfied (use --upgrade to upgrade): python-axolotl-curve25519 in /usr/local/lib/python2.7/dist-packages (from python-axolotl>=0.1.7->yowsup2)                                                
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/lib/python2.7/dist-packages (from protobuf>=2.6,<3.0.0-alpha-2->python-axolotl>=0.1.7->yowsup2)                                       
Cleaning up...                                                                                                                                                                                                     
root@h2476922:/home/scripts/wabot/test/whatsapp-bot-seed# python src/server.py                                                                                                                                     
Traceback (most recent call last):                                                                                                                                                                                 
  File "src/server.py", line 10, in <module>                                                                                                                                                                       
    from yowsup.layers import YowLayerEvent, YowParallelLayer                                                                                                                                                      
ImportError: No module named yowsup.layers 

if im using the yowsup-cli command its working fine

changing to python3 the bot starts, changing back to 2.7 i get the yowsup error

joaoricardo000 commented 8 years ago

If you run the "pip" out of an virtualenv, it will install on default python, in your case 3.4. Try this steps:


> virtualenv -p /usr/bin/python2.7 venv (or where is your python2.7 bin)
> source venv/bin/activate  (activate the virtualenv)
> pip install -r opt/requirements.txt (install the requirements on the virtualenv)
> python src/server.py  (with the venv activated, run...)
e0xify commented 8 years ago

cant use the virtualenv command, cause its not recogized, i removed python 3 and used alias command to use python2.7.

when i install the requirements now, i get this error by installing pillow:

/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libjpeg.a(jcapimin.o): relocation R_X86_64_32S againstjpeg_natural_order' can not be used when making a shared object; recompile with -fPIC
/usr/lib/x86_64-linux-gnu/libjpeg.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------                                                                                                                                                                       

Command "/usr/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-build-Y3DtTh/pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec') )" install --record /tmp/pip-NYA1X1-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-Y3DtTh/pillow`

like 2 hours, getting it not fixxed

joaoricardo000 commented 8 years ago

Yes.. I tried to change the default python version on Ubuntu about 3 years ago... I remember it really was a pain, and it was the only time that I tried it.
I'm working on a Dockerfile to isolate all enviroments requirement for the bot. Until then I wish you good luck...

e0xify commented 8 years ago

installed virtualenv installed dependencies working fine

joaoricardo000 commented 8 years ago

Nice!

e0xify commented 8 years ago

@joaoricardo000 what are you using for tts?

is there a way to get it slower? or support multilanguage?