tgalal / yowsup

The WhatsApp lib
GNU General Public License v3.0
7.09k stars 2.23k forks source link

Sending image failed: <p>Invalid media download request</p> #1746

Open ragowthaman opened 8 years ago

ragowthaman commented 8 years ago

Hello , I am trying to implement sending image (no need for encryption).

No handlers could be found for logger "yowsup.layers.protocol_media.mediauploader"

Digging bit deep, I see it give the <p>Invalid media download request</p> error

Any help would be greatly appreciated.

Thanks Gowthaman

my layer.py

Class GowImageSendLayer(YowInterfaceLayer):

    @ProtocolEntityCallback("success")
    def onSuccess(self, successProtocolEntity):
        print "in image success"
        # def requestImageUpload(self):
        imagePath = "/Users/gramasamy/Desktop/cake.jpg"
        self.demoContactJid = "919003832999@s.whatsapp.net"
        self.filePath = imagePath
        requestUploadEntity = RequestUploadIqProtocolEntity("image", filePath=imagePath)
        self._sendIq(requestUploadEntity, self.onRequestUploadResult, self.onRequestUploadError)

    def onRequestUploadResult(self, resultRequestUploadIqProtocolEntity, requestUploadIqProtocolEntity):
        mediaUploader = MediaUploader(self.demoContactJid, self.getOwnJid(), self.filePath,
                                      resultRequestUploadIqProtocolEntity.getUrl(),
                                      resultRequestUploadIqProtocolEntity.getResumeOffset(),
                                      self.onUploadSuccess, self.onUploadError)
        mediaUploader.start()

    def onRequestUploadError(self, errorRequestUploadIqProtocolEntity, requestUploadIqProtocolEntity):
        print("Error requesting upload url")

    def onUploadSuccess(self, filePath, jid, url):
        #convenience method to detect file/image attributes for sending, requires existence of 'pillow' library
        entity = ImageDownloadableMediaMessageProtocolEntity.fromFilePath(filePath, url, None, to)
        self.toLower(entity)

    def onUploadError(self, filePath, jid, url):
        print("Upload file failed!")

stack.py

from yowsup.stacks import YowStackBuilder
from yowsup.layers.auth import AuthError
from yowsupCustomLayers import EchoLayer, SendLayer, LogLayer, GowImageSendLayer
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer
from yowsup.env import YowsupEnv
# import yowlayer_store

credentials = ("91xxxxxx", "xxxxxxxx/xxxxx=") # replace with your phone and password

if __name__==  "__main__":
    stackBuilder = YowStackBuilder()

    stack = stackBuilder\
        .pushDefaultLayers(True)\
        .push(GowImageSendLayer)\
        .build()

    stack.setCredentials(credentials)
    stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))   #sending the connect signal
    stack.loop() #this is the program mainloop
ragowthaman commented 8 years ago

The code (>99%) was from wiki @steffen vogel and @tgalal

dargmuesli commented 8 years ago

What is the output of the debugger? Add

import logging

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)

to the layer.py.

tomatensuppe commented 8 years ago

and now ? whats the solution ?