joaoricardo000 / whatsapp-bot-seed

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

Permission problems/errors with /s /t /i weburl while pictureurl and youtube works #28

Closed x23piracy closed 8 years ago

x23piracy commented 8 years ago

Hi,

i have the same issue and i don't think that this is a filesystem problem its seems that it's another pakage used that will not work as root: http://pastebin.com/9WNJP9pU

You are not allowed to run this app with root permissions. If running without sudo doesn't work, you can either fix your permission problems or change where npm stores global packages by putting ~/npm/bin in your PATH and running: npm config set prefix ~/npm

I've done what the error message told me also i uninstalled all npm modules and reinstalled them via nvm without needed root but anyway the error persists.

The above happens while using /s

When using /t the bot answers only {!} but an mp3 file is been created under /tmp: http://i.imgur.com/9F0242q.png

When using /i i get the error: TypeError: 'NoneType' object has no attribute 'getitem' http://pastebin.com/kFVuaKkv

When sending web url like http://google.de it same error like with /s and permission problem with the /tmp path

What works is http links to pictures and youtube videos.

Any ideas which modules are the problem here and howto fix this issues?

Regards X23

x23piracy commented 8 years ago

Hi,

i could fix /i and /t by the pull request available but /s and weburl still not working (permission problem see above) Please help.

Regards X23

ghost commented 8 years ago

You can use CutyCapt instead of pageres-cli, just go to the terminal and type:

sudo apt-get install xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps && sudo apt-get install cutycapt

After installing CutyCapt, go to utils/media_sender.py and change pageres "%s" 1024x2300 --crop --filename=%s to xvfb-run --server-args="-screen 0, 1024x768x24" cutycapt --url=%s --out=%s --min-width=1024 --min-height=768 in line 174

Hope it works ;)

ghost commented 8 years ago

About the permission problem with /tmp folder, you need to change media_storage_path = "/tmp/" in config.py to media_storage_path = "/home/tmp/" by example, that works for me.

x23piracy commented 8 years ago

Hi,

thank you for the answers, when i change the path away from /tmp to /home/tmp i still get permission errors: http://pastebin.com/wrfxyFvH

I will now try using CutyCapt

Regards X23

x23piracy commented 8 years ago

Hi,

i've now also made the changes regarding to cutycapt like you told me but i still have permission errors: http://pastebin.com/zT9LqWiU

How do i install npm or it's modules without root?

This can be seen in the shell without the changes to media_sender.py:

You are not allowed to run this app with root permissions. If running without sudo doesn't work, you can either fix your permission problems or change where npm stores global packages by putting ~/npm/bin in your PATH and running: npm config set prefix ~/npm

I found this on the web: http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo

Regards X23

ghost commented 8 years ago

A "segmentation fault error" happens with only a few websites, for example, a large website can cause that error. Try another website, such as google.com (with CutyCapt)

x23piracy commented 8 years ago

Hi,

i use CutyCapt but i still receive this when pasting normal weblinks: This happens to every link i try and /tmp is readable writeable since every other function that is writing and reading to /tmp is working.

router.py [INFO]2016-01-27 22:42:56,672[4917xxxxxxxxxx@s.whatsapp.net] http://gmx.de You are not allowed to run this app with root permissions. If running without sudo doesn't work, you can either fix your permission problems or change where npm stores global packages by putting ~/npm/bin in your PATH and running: npm config set prefix ~/npm

See: https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md _mediasender.py [ERROR][2016-01-27 22:43:04,245] Either specified path does not exist, or yowsup doesn't have permission to read: /tmp/058b30fc5366a27ef0fc9ed2b345286614539309.png Traceback (most recent call last): File "/opt/whatsapp-bot-seed-master/src/utils/media_sender.py", line 53, in send_by_url self.send_by_path(jid, file_path, caption) File "/opt/whatsapp-bot-seed-master/src/utils/media_sender.py", line 65, in send_by_path entity = RequestUploadIqProtocolEntity(self.MEDIA_TYPE, filePath=path) File "/usr/local/lib/python2.7/dist-packages/yowsup/layers/protocol_media/protocolentities/iq_requestupload.py", line 27, in init assert os.path.exists(filePath), "Either specified path does not exist, or yowsup doesn't have permission to read: %s" % filePath AssertionError: Either specified path does not exist, or yowsup doesn't have permission to read: /tmp/058b30fc5366a27ef0fc9ed2b345286614539309.png

Everything else works fine, what is the problem here?

Regards X23

ghost commented 8 years ago

I don't know what happens, sorry :/

x23piracy commented 8 years ago

Hi,

it seems that npm cannot run as root:

You are not allowed to run this app with root permissions. If running without sudo doesn't work, you can either fix your permission problems or change where npm stores global packages by putting ~/npm/bin in your PATH and running: npm config set prefix ~/npm

But howto fix that? i already added ~/npm/bin to path and executed: npm config set prefix ~/npm

My defaut linux machine account is root. :( Maybe i need to add anoter account to the machine (non root) and try with that but how does it work simply adding a user, logon with it and run the bot is the goal?

Regards X23

x23piracy commented 8 years ago

Hi,

when i call: pageres in shell i get:

root@NbI-1527:/opt/whatsapp-bot-seed-master/src/utils# pageres You are not allowed to run this app with root permissions. If running without sudo doesn't work, you can either fix your permission problems or change where npm stores global packages by putting ~/npm/bin in your PATH and running: npm config set prefix ~/npm

See: https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md

x23piracy commented 8 years ago

Hi,

i hacked the pageres root permission away with commenting sudoBlock() away from cli.js :D But still errors:

fyi it doesnt matter of file path is /tmp or /home/tmp, files are not created thats the reason it cannot access them.

with pageres

router.py [INFO]2016-01-27 23:28:26,490[491782330088@s.whatsapp.net] http://www.google.de TypeError: Object # has no method 'isAbsolute' at Pageres.create (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/util.js:381:24) at /usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:137:33 at Array.map (native) at Pageres.run$ (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/dist/index.js:109:64) at tryCatch (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/node_modules/babel-runtime/regenerator/runtime.js:72:40) at GeneratorFunctionPrototype.invoke as _invoke at GeneratorFunctionPrototype.prototype.(anonymous function) as next at tryCatch (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/node_modules/babel-runtime/regenerator/runtime.js:72:40) at invoke (/usr/local/lib/node_modules/pageres-cli/node_modules/pageres/node_modules/babel-runtime/regenerator/runtime.js:146:20) at /usr/local/lib/node_modules/pageres-cli/node_modules/pageres/node_modules/babel-runtime/regenerator/runtime.js:191:11 _mediasender.py [ERROR][2016-01-27 23:28:33,569] Either specified path does not exist, or yowsup doesn't have permission to read: /home/tmp/108eca7b644e2c5e09853619bc416ed014539337.png

with CutyCapt

router.py [INFO]2016-01-27 23:30:00,715[491782330088@s.whatsapp.net] http://www.google.de _mediasender.py [ERROR][2016-01-27 23:30:10,769] Either specified path does not exist, or yowsup doesn't have permission to read: /tmp/108eca7b644e2c5e09853619bc416ed014539338.png Traceback (most recent call last): File "/opt/whatsapp-bot-seed-master/src/utils/media_sender.py", line 53, in send_by_url self.send_by_path(jid, file_path, caption) File "/opt/whatsapp-bot-seed-master/src/utils/media_sender.py", line 65, in send_by_path entity = RequestUploadIqProtocolEntity(self.MEDIA_TYPE, filePath=path) File "/usr/local/lib/python2.7/dist-packages/yowsup/layers/protocol_media/protocolentities/iq_requestupload.py", line 27, in init assert os.path.exists(filePath), "Either specified path does not exist, or yowsup doesn't have permission to read: %s" % filePath AssertionError: Either specified path does not exist, or yowsup doesn't have permission to read: /tmp/108eca7b644e2c5e09853619bc416ed014539338.png

Argh :) Any ideas?

Regards X23

e0xify commented 8 years ago

same issue, did u get it fixxed?

joaoricardo000 commented 8 years ago

This is a user permission problem. First make a test: log in with the same user that runs the bot. Check if a pageres (or CutyCapt) command runs ok on command line, if it have the necessary permissions read/write on the output folder (default is /tmp/, so it should) pageres have a problem of not allowing it to be run with a sudo, probably that's the issue.

e0xify commented 8 years ago

today is not my day. fixxed it by creating a temp dir in scriptfolder and givivng it chmod 777, but running into the next issue:

tts is working, utube, image sending is working. now the search is not working..

_router.py_ [INFO][2016-01-28 15:47:17,846] (GROUP)[4915142540521@s.whatsapp.net]-[4915142540521-1453975202@g.us] /s looking _connectionpool.py_ [INFO][2016-01-28 15:47:17,848] Starting new HTTP connection (1): ajax.googleapis.com _router.py_ [ERROR][2016-01-28 15:47:18,382] Error routing message: /s looking Message: ID: 1453992436.--325 From: 4915142540521-1453975202@g.us Type: text Timestamp: 1453992437 Participant: 4915142540521@s.whatsapp.net Body: /s looking Traceback (most recent call last): File "/home/scripts/wabot/test/whatsapp-bot-seed/src/router.py", line 72, in handle_callback data = callback(message, match) File "/home/scripts/wabot/test/whatsapp-bot-seed/src/views/google.py", line 29, in google_search page_url = urllib.unquote(req.json()["responseData"]["results"][0]["url"]) AttributeError: 'module' object has no attribute 'unquote'

@joaoricardo000 any idea mate?

joaoricardo000 commented 8 years ago

Wow.. any idea! Why would this not work?

> import urllib
> urllib.unquote
<function urllib.unquote>

urllib is python default..

e0xify commented 8 years ago

got it fixxed by updating all pip packages pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U

the permission error seems to be still existing. the thing is, videos will be downloaded to that directory and can be sent.

the images will not even get created. it says: "cant read file home/bla/bot/temp/image.jpg" but the image.jpg is not even in the directory.

File "/home/scripts/wabot/test/whatsapp-bot-seed/src/utils/media_sender.py", line 52, in send_by_url self.send_by_path(jid, file_path, caption) File "/home/scripts/wabot/test/whatsapp-bot-seed/src/utils/media_sender.py", line 64, in send_by_path entity = RequestUploadIqProtocolEntity(self.MEDIA_TYPE, filePath=path) File "/home/scripts/wabot/test/whatsapp-bot-seed/venv/local/lib/python2.7/site-packages/yowsup/layers/protocol_media/protocolentities/iq_requestupload.py", line 27, in __init__ assert os.path.exists(filePath), "Either specified path does not exist, or yowsup doesn't have permission to read: %s" % filePath AssertionError: Either specified path does not exist, or yowsup doesn't have permission to read: /home/scripts/wabot/test/whatsapp-bot-seed/temp/2b6f793df061f0a6dd577683d33ddfab14539941.png

2b6f793df061f0a6dd577683d33ddfab14539941.png does not exist

andremacola commented 8 years ago

Any idea how to solve this problem? /search is not working. Tried with cutycapt and pageres.

andremacola commented 8 years ago

Problem Solved:

Using cutycapt Add .png after %s

cmd = 'xvfb-run --server-args="-screen 0, 1024x768x24" cutycapt --url=%s --out=/home/whatsapp/tmp/%s.png --min-width=1024 --min-height=768' % (page_url, file_name)

x23piracy commented 8 years ago

confirmed, well done :)

slozano95 commented 8 years ago

@andremacola @x23piracy how did you get it fixed? where do I have to add the @andremacola solution?? Thanks