Skip to content
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

Fix error in logging: could not concat bytes and string #2027

Closed
wants to merge 4 commits into from
Closed

Fix error in logging: could not concat bytes and string #2027

wants to merge 4 commits into from

Conversation

mniak
Copy link

@mniak mniak commented May 4, 2017

When a media was received, an error was thrown because of this logging issue.
This is my proposed solution, that works for me, but I don't know if it satisfies

@mniak
Copy link
Author

mniak commented May 5, 2017

#2016

This pull request fixes the receipt of the field media_key and this way you are already able to echo the images. For this, in the EchoLayer you will need to add the mediaKey parameter like this:

    def send_image_echo(self, entity):
        echo = ImageDownloadableMediaMessageProtocolEntity(
            entity.getMimeType(), entity.fileHash, entity.url,
            entity.ip,
            entity.size, entity.fileName, entity.encoding,
            entity.width, entity.height,
            entity.getCaption(), entity.mediaKey,
            to=entity.getFrom(), preview=entity.getPreview())

        print("Echoing image")
        self.toLower(echo)

@bombadiltom
Copy link

Any other pull requests needed here?
If i fetch this one into master, i get the following error at login:
val = ''.join(['%' + hex(b)[2:] for b in val])
TypeError: hex() argument can't be converted to hex

@mniak
Copy link
Author

mniak commented May 5, 2017

I really do not know how should I encode these bytes. I was scared of breaking this XML, but since it's only for logging, maybe we could just .encode() these bytes not caring about "escaping" them. They wont be parsed again as XML.

@mniak
Copy link
Author

mniak commented May 5, 2017

@bombadiltom are you using python2.7? I was using 3 and this error was not thrown to me.
Are you doing something different at login?

I will test in 2.7

@bombadiltom
Copy link

@mniak Python 2.7.9, yowsup-cli demos -c /etc/yowsup.config -y, then /L

@bombadiltom
Copy link

@mniak: Python3:
[offline]:/L
Auth: Logged in!
[connected]:/image send 12345 /space/doorbird/lastmotion.jpg
[...]
File "/usr/local/lib/python3.4/dist-packages/yowsup2-2.5.2-py3.4.egg/yowsup/layers/init.py", line 163, in processIqRegistry
errorClbk(protocolTreeNode, originalIq)
File "/usr/local/lib/python3.4/dist-packages/yowsup2-2.5.2-py3.4.egg/yowsup/layers/axolotl/layer_base.py", line 81, in onError
errorClbk(errorNode, getKeysEntity)
TypeError: () takes 0 positional arguments but 2 were given

BTW: Did you test your pull request with pull request 555 already? What's the best way to easilly merge them together?

@langioletto
Copy link

I applied the changes and I launched the layer.py again

`File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.2-py2.7.egg/yowsup/layers/axolotl/layer_control.py", line 34, in send
self.toLower(node)

File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.2-py2.7.egg/yowsup/layers/init.py", line 84, in toLower
self.__lower.send(data)

File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.2-py2.7.egg/yowsup/layers/logger/layer.py", line 8, in send
logger.debug("tx:\n%s" % ldata)

File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.2-py2.7.egg/yowsup/structs/protocoltreenode.py", line 90, in str
return self.toString()

File "/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.2-py2.7.egg/yowsup/structs/protocoltreenode.py", line 56, in toString
val = ''.join(['%' + hex(b)[2:] for b in val])
TypeError: hex() argument can't be converted to hex
`

The issue is generated with changes to: protocoltreenode.py

@langioletto
Copy link

langioletto commented May 10, 2017

News?

With python2.7 these changes do not work, can you confirm?

Thanks

@Aragur
Copy link

Aragur commented May 13, 2017

So the image echoing is working. But I can't get it working to send a image from filePath
Exception thrown:
'https://longurl' has type <class 'str'>, but expected one of: ((<class 'bytes'>,),)

If I convert the URL via .encode i get following thrown:
None has type <class 'NoneType'>, but expected one of: ((<class 'bytes'>,),)
(A log of the converted value returns b https://longurl)

Note 1: URL was shortened to improve readability
Note 2: Using Python 3.4

@luidna
Copy link

luidna commented May 19, 2017

Removed the logging modification from pull request.
Only media echo fixes included

@mniak
Copy link
Author

mniak commented Jan 2, 2019

Anyone?

@mniak
Copy link
Author

mniak commented Jan 2, 2019

As no one is accepting this, I will then close this PR.

@mniak mniak closed this Jan 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants