yowsup icon indicating copy to clipboard operation
yowsup copied to clipboard

method "profile_setPicture" don't work

Open Marcorele opened this issue 12 years ago • 27 comments

Hi,

since few days, "profile_setPicture" don't work.

No error messages returned but the profile picture stay the same.

Anyone have the same problem?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Marcorele avatar Jul 06 '14 12:07 Marcorele

hello?

Marcorele avatar Jul 09 '14 12:07 Marcorele

This is already solved in other issue. Search tab above.

#!/usr/bin/python

import argparse, sys, os, csv
from Yowsup.Common.utilities import Utilities
from Yowsup.Common.debugger import Debugger
from Yowsup.Common.constants import Constants
from Yowsup.Contacts.contacts import WAContactsSyncRequest
from Yowsup.connectionmanager import YowsupConnectionManager

import threading,time, base64

########## DO NOT COMMIT THIS FILE WITH YOUR CREDENTIALS ###########
#.....................WhatsApp Account Config.......................

nickname = ""
username = ""
password = ""
path = "/Users/mgp25/Desktop/yowsup-master/src/image.jpeg" #Full image path

#....................................................................

password = base64.b64decode(bytes(password.encode('utf-8')))
Debugger.enabled = True if '-d' in sys.argv else False

def login(username, password):
    print "[] Logging in as %s (%s)\n" % (nickname, username)
    methodsInterface.call("auth_login", (username, password))

def onAuthSuccess(username):
    print("Authed!!\n\n")
    methodsInterface.call("ready")
    methodsInterface.call("presence_sendAvailableForChat", (nickname,))
    methodsInterface.call("profile_setPicture", (path,))

    t = 5
    i = 0
    while i < t:
        time.sleep(0.5)
        i=i+1

def onAuthFailed(username, err):
    print("Auth Failed!")



########################### BIND EVENTS #############################   
connectionManager = YowsupConnectionManager()
signalsInterface = connectionManager.getSignalsInterface()
methodsInterface = connectionManager.getMethodsInterface()
connectionManager.setAutoPong(True)

signalsInterface.registerListener("auth_success", onAuthSuccess)
signalsInterface.registerListener("auth_fail", onAuthFailed)
#####################################################################

login(username, password)

mgp25 avatar Jul 09 '14 12:07 mgp25

Your script does not work. The method "profile_setPicture" is not working.

elrodrix avatar Jul 09 '14 18:07 elrodrix

of course it works, but all you have to do is to fix it, its really simple, i did it for myself. Im not a genius at programming and stuff, but with curiosity and patience you will be surprised what you might get to do.

I'll wait for someone to get into it, if no one do it, ill send a pull request.

Pss.. want a hint? : bGluZSA2MzggY29ubmVjdGlvbm1hbmFnZXI=

Regards :)

mgp25 avatar Jul 09 '14 23:07 mgp25

I messed a little with the code in the last few hours haha. I'll just leave it here. With this you have to be able to set a new profile picture, maybe little changes ;)

This is just a hint, not the solution xd

def makeId(self,prefix):
        self.iqId += int(time.time()) .... # This is for better id...
....
    def sendSetPicture(self, jid, imagePath):

        f = open(imagePath, 'rb')
        imageData = f.read()
        imageData = bytearray(imageData)
        f.close()

        idx = self.makeId("setphoto-")
        self.readerThread.requests[idx] = self.readerThread.parseSetPicture

        picture = ProtocolTreeNode("picture", None, None, imageData)

        icon = self.createIconGD(imagePath) # create thumbnail of the image :) You will need to create that function :D it took time to me :'D
        thumb = ProtocolTreeNode("picture", {"type":"preview"}, None, icon)

        iqNode = ProtocolTreeNode("iq",{"id":idx,"to":jid,"type":"set", "xmlns":"w:profile:picture"}, {picture, thumb}, None)

        self._writeNode(iqNode)

Output with yowsup should be like:

<iq id="setphoto-1404978598" to="[email protected]" type="set" xmlns="w:profile:picture">
<picture>IMAGE</picture>
<picture type="preview">THUMBNAIL</picture>
</iq>

mgp25 avatar Jul 10 '14 10:07 mgp25

@mgp25 did you have any solution please?

Marcorele avatar Jul 21 '14 23:07 Marcorele

Yes, first use WAuth-2 instead, then you have to create a valid xml. Most of the attributes have been moved to parent node.

mgp25 avatar Jul 21 '14 23:07 mgp25

@mgp25 how to use WAuth-2?

elrodrix avatar Jul 22 '14 18:07 elrodrix

wauth2

Go to wauth2 and there you go. You will need to make a couple changes, but it will work

mgp25 avatar Jul 22 '14 18:07 mgp25

createIconGD def createIconGD(self, imagePath, size=100, raw=False): img = Image.open(imagePath)
width, height = img.size img_thumbnail = imagePath + '_thumbnail'

    if width > height:
        nheight = float(height) / width * size
        nwidth = size
    else:
        nwidth = float(width) / height * size
        nheight = size

    img.thumbnail((nwidth, nheight), Image.ANTIALIAS)
    img.save(img_thumbnail, 'JPEG')

    with open(img_thumbnail, 'rb') as imageFile:
        raw = base64.b64encode(imageFile.read())

    return raw

debianitram avatar Jul 26 '14 23:07 debianitram

@debianitram nice, you are the first to realize that the code can be easily ported from WhatsAPI :) For all people, this function 'createIconGD' can be found in WhatsAPI in func.php.

The next step you are going to face is the:

BinTreeNodeReader:  Incoming
BinTreeNodeReader:  
<stream:error>
  <xml-not-well-formed>
</xml-not-well-formed>

Also you can change toString in protocolTreeNode, when sending some media just print the bytes not the byte content:

    def toString(self):
        try:
            out = "<"+self.tag;
            if self.attributes is not None:
                for key,val in self.attributes.items():
                    out+= " "+key+'="'+val+'"'
            out+= ">\n";
            if self.data is not None:
                if len(self.data) <= 1024:
                    out += self.data;
                else:
                    out += str(len(self.data)) + " byte data";

            if self.children is not None:
                for c in self.children:
                    out+="  "+c.toString();
            #print sel
            out+= "</"+self.tag+">\n"
            return out
        except TypeError:
            print("ignored toString call, probably encountered byte")
        except UnicodeDecodeError:
            print("ingnored toString call, encountered unicode error")

mgp25 avatar Jul 27 '14 07:07 mgp25

Hi, i made the changes as above, except going to wauth2 branch:

BinTreeNodeWriter:  Outgoing
BinTreeNodeWriter:  
 <iq to="[email protected]" xmlns="w:profile:picture" type="set" id="set_picture_1">
  <picture type="preview">
4340 byte data</picture>
  <picture>
5298 byte data</picture>
</iq>

And i get the error=501 not implemented answer. What wonders me, is that the child notes are not in order as i put them into the child node list. Same appears to be the case also with the attributes. If i change to a [...] bracket list for the childs, still the same wrong order. I tried the same with WhatsAPI and i get it all working [ https://github.com/venomous0x/WhatsAPI/issues/637 ]

sire42 avatar Sep 03 '14 21:09 sire42

wrong node. for wauth1 you need

 <iq to="[email protected]" type="set" id="set_picture_1">
  <picture type="preview" xmlns="w:profile:picture">
4340 byte data</picture>
  <picture xmlns="w:profile:picture">
5298 byte data</picture>
</iq>

understood?

CODeRUS avatar Sep 03 '14 21:09 CODeRUS

BinTreeNodeWriter:  Outgoing
BinTreeNodeWriter:  
 <iq to="[email protected]" type="set" id="set_picture_1">
  <picture xmlns="w:profile:picture">
5298 byte data</picture>
  <picture xmlns="w:profile:picture" type="preview">
4340 byte data</picture>
</iq>

Gives me error=406 not acceptable.

sire42 avatar Sep 03 '14 21:09 sire42

i dont remember exactly, sorry, but try to set xmlns only to one node with preview

CODeRUS avatar Sep 03 '14 21:09 CODeRUS

406 i could consider wauth2 branch, but the commit comment: "Send is still not working (encoding problem?)" Kind of does not attract me :P

sire42 avatar Sep 03 '14 21:09 sire42

yep, it's not ready to use and nobody have time to look at :D you shouldn't receive 406. something wrong with your node or pictures (?)

CODeRUS avatar Sep 03 '14 22:09 CODeRUS

This one is working for me (C++ code for project still using WAUTH-1) http://paste.ubuntu.com/8227193/

CODeRUS avatar Sep 03 '14 22:09 CODeRUS

Thanks for the snipped, but no luck

BinTreeNodeWriter:  Outgoing
BinTreeNodeWriter:  
 <iq to="[email protected]" type="set" id="set_picture_2">
  <picture xmlns="w:profile:picture">
5298 byte data</picture>
  <picture xmlns="w:profile:picture" type="preview">
4340 byte data</picture>
</iq>

-> 406

sire42 avatar Sep 03 '14 22:09 sire42

I have a basic question regarding encoding of the image file: base64 or something else? mgp25 suggested (27 Jul) to replace in protocolTreeNode the binary content with the number of bytes (which is something completely different) in order to avoid exception "ignored toString call, probably encountered byte". The code snippet from CODeRus "pictureNode.setData(imageBytes)" seems to be more reasonable but it is no valid python code as far as the data type of imageBytes is not str(). Anyhow, I could not convince the routine to work.

konradhennen avatar Oct 05 '14 09:10 konradhennen