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

sendfile only works with image=True #34

Open
Nixellion opened this issue Nov 20, 2016 · 17 comments
Open

sendfile only works with image=True #34

Nixellion opened this issue Nov 20, 2016 · 17 comments
Labels

Comments

@Nixellion
Copy link

I can only send images files with ch.sendfile, using this code:

from skpy import Skype
sk = Skype(login, pass) 
ch = sk.contacts["nixellion"].chat 
ch.sendFile(open(pathToFile, "rb"), fileName, image=True) # file upload

So, if I use image=True, then all images are sent correctly. If I pass a non-image file with image=True, then skype receives it but does not download, just draws a big exclamation mark.

But if I send any file with image=False, then just nothing happens.

@Terrance
Copy link
Owner

Can't seem to reproduce here -- images received fine with or without the image flag set, and both are happy to be downloaded.

image

Presumably you're not getting an exception whilst sending?

Would be useful to see the raw message from both ends. sendFile() returns a SkypeFileMsg -- the content property is the HTML sent to Skype. You can then call getMsgs() to retrieve the processed message and compare its content.

If I pass a non-image file with image=True, then skype receives it but does not download, just draws a big exclamation mark.

That is reasonable server behaviour, probably Skype providing a default thumbnail for a non-image.

@Nixellion
Copy link
Author

Nixellion commented Nov 20, 2016

Here is what I get.
Content seems to be identical. But it just don't receive this file.
I'm using Python 3.4, by the way.

And I can proceed to the link in this message, and download the file from there. But I need it to be sent through skype...

Content: <URIObject type="File.1" uri="https://api.asm.skype.com/v1/objects/0-neu-d3-XXXXXXXXX" url_thumbnail="https://api.asm.skype.com/v1/objects/0-neu-d3-XXXXXXXXX/views/thumbnail"><Title>Title: a.srt</Title><Description>Description: a.srt</Description><OriginalName v="a.srt"/><FileSize v="184606"/><a href="https://login.skype.com/login/sso?go=webclient.xmm&docid=0-neu-d3-XXXXXXXXX">https://login.skype.com/login/sso?go=webclient.xmm&docid=0-neu-d3-XXXXXXXXX</a></URIObject>

UPDATE:
I logged into the sender account, the one i'm using with skpy. And I can see all those files as sent, but I don't see them from the receiving account... weird

UPDATE 2:
Okay... I have 2 PCs now, one has the sender desktop client online, another has the receiver. I run the script (i know it does not require desktop client), and i see the file being sent but not received...

Then I logged the sender off and logged into receiver again - and I received all those files. But I still don't see them on another pc. Wtf is going on, skype :D

@Terrance
Copy link
Owner

Content seems reasonable... 🤔

The receiving account: which clients are you using? Does Skype for Web (or SkPy) handle the file and download as expected? Different to native (desktop/mobile) clients?

If an image is sent from the receiving account, can the sending account download it (either via Skype for Web, or in SkPy)?

Bonus: if you send an image via Skype for Web, and retrieve it in SkPy, is the content in the same format as the above?

@Nixellion
Copy link
Author

Nixellion commented Nov 21, 2016

I'm using windows desktop skype client, I believe it's latest version.

If I send files between desktop clients everything works as expected.

And skype for web actually seems to be downloading files correctly. However after that I try to get the str(msg.file) to pass the links to the client to at least download them from the link, and it works with desktop, but it fails in skype for web with this error:

CMD Error: ('400 response from POST https://bn2-client-s.gateway.messenger.live.com/v1/users/ME/conversations/8:username/messages', )
Traceback (most recent call last):
  File "\cmds.py", line 51, in process
    self.ms = ch.sendFile(open(path, "rb"),filename , image=img)
  File "D:\Projects\Python\prjname_AI\Code\prjnameAI_Server\skpy\chat.py", line 176, in sendFile
    return self.sendRaw(content=body, messagetype=msgType)
  File "D:\Projects\Python\prjname_AI\Code\prjnameAI_Server\skpy\chat.py", line 81, in sendRaw
    auth=SkypeConnection.Auth.RegToken, json=msg).json().get("OriginalArrivalTime")
  File "D:\Projects\Python\prjname_AI\Code\prjnameAI_Server\skpy\conn.py", line 215, in __call__
    raise SkypeApiException("{0} response from {1} {2}".format(resp.status_code, method, url), resp)
skpy.core.SkypeApiException: ('400 response from POST https://bn2-client-s.gateway.messenger.live.com/v1/users/ME/conversations/8:username/messages', )

@Terrance
Copy link
Owner

Can you enable HTTP debugging (SKPY_DEBUG_HTTP=1 in your environment) and reproduce that 400 error?

@Nixellion
Copy link
Author

Nixellion commented Nov 21, 2016

Well, yes, but what should I look for there?

And is it posible to set online status with skpy?

@Terrance
Copy link
Owner

It would be useful to know what's causing that error, which I won't really know unless I can see exactly what's being sent and received...

SkPy essentially mocks Skype for Web, so if it works there then SkPy probably isn't mocking correctly, otherwise it's probably a bug in Skype for Web.

And is it posible to set online status with skpy?

Skype.setPresence()

@Terrance
Copy link
Owner

Terrance commented Dec 8, 2016

@Nixellion Is this still an issue for you?

@Nixellion
Copy link
Author

Well, yeah, did not fix itself :) I did not have time to research it more, but it's still not working.

@Terrance
Copy link
Owner

I'm not sure how to reproduce this -- I've sent various files and images, and they all seem to be received and displayed correctly in SkPy, Skype for Web, and Skype for Windows.

I can see all those files as sent, but I don't see them from the receiving account

Given you can see the files on the sending end, and the API should give you the same message content on either end, I'm inclined to say that is a server bug with Skype?

The 400 error -- if you can still reproduce that, can you include the HTTP request/response here, as noted before? Can't tell much from the traceback alone...

@Terrance
Copy link
Owner

Terrance commented Jan 9, 2017

I'm going to close this for now. If you can get the above, I might be able to debug this more.

@Terrance Terrance closed this as completed Jan 9, 2017
@Nixellion
Copy link
Author

Yes, I get this ALL the time.
How do I get HTTP request\response? I don't think it's printed by logger. Or I did not notice it.

I have other things to do right now, but I'll post it when I get back to it.

@Terrance
Copy link
Owner

Terrance commented Jan 9, 2017

See above, SKPY_DEBUG_HTTP=1 in your env. Should probably switch to the logging module.

@Terrance
Copy link
Owner

Reopening as I've managed to repro this now -- Skype for Web and Skype on Android behave, but a non-image file is MIA on Skype for Windows.

However, looking at the message body, the image markup has changed since this was implemented (removed empty Title and Description tags, added some help text, fallback link is now under login.skype.com), but the file code appears to be correct. I've included samples of both types below. Note that message types are still accurate (RichText/UriObject if image, else RichText/Media_GenericFile).


Picture via web:

<URIObject type="Picture.1"
           uri="https://api.asm.skype.com/v1/objects/0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
           url_thumbnail="https://api.asm.skype.com/v1/objects/0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/views/imgt1">
    To view this shared photo, go to:
    <a href="https://login.skype.com/login/sso?go=webclient.xmm&amp;pic=0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
		https://login.skype.com/login/sso?go=webclient.xmm&amp;pic=0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>
    <OriginalName v="image.png"/>
    <meta type="photo" originalName="image.png"/>
</URIObject>

Picture via SkPy:

<URIObject type="Picture.1"
           uri="https://api.asm.skype.com/v1/objects/0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
           url_thumbnail="https://api.asm.skype.com/v1/objects/0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/views/imgt1">
    <Title/>
    <Description/>
    <OriginalName v="image.png"/>
    <a href="https://api.asm.skype.com/s/i?0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
		https://api.asm.skype.com/s/i?0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>
    <meta type="photo" originalName="image.png"/>
</URIObject>

File via web:

<URIObject type="File.1"
           uri="https://api.asm.skype.com/v1/objects/0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
           url_thumbnail="https://api.asm.skype.com/v1/objects/0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/views/thumbnail">
    <Title>Title: text.txt</Title>
    <Description> Description: text.txt</Description>
    <a href="https://login.skype.com/login/sso?go=webclient.xmm&amp;docid=0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
		https://login.skype.com/login/sso?go=webclient.xmm&amp;docid=0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>
    <OriginalName v="text.txt"/>
    <FileSize v="5"/>
</URIObject>

File via SkPy:

<URIObject type="File.1"
           uri="https://api.asm.skype.com/v1/objects/0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
           url_thumbnail="https://api.asm.skype.com/v1/objects/0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/views/thumbnail">
    <Title>Title: text.txt</Title>
    <Description>Description: text.txt</Description>
    <OriginalName v="text.txt"/>
    <FileSize v="5"/>
    <a href="https://login.skype.com/login/sso?go=webclient.xmm&docid=0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
		https://login.skype.com/login/sso?go=webclient.xmm&docid=0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</a>
</URIObject>

@Terrance Terrance reopened this Jul 13, 2017
@Terrance Terrance added bug and removed question labels Jul 13, 2017
@Terrance
Copy link
Owner

Terrance commented Jul 13, 2017

Actually, looking closer at Skype for Web, when you send a file/image, there are a number of calls to https://api.asm.skype.com/v1/objects/0-xeu-dx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/views/imgt1/status, which tells you when the file upload and the preview are finished processing. Only after they're both ready does the message actually send in the web client.

SkPy performs no such checks, which means it might be sending messages before they're ready to fetch from the receiving clients. Adding in some artificial delay doesn't seem to help.

@myself521
Copy link

myself521 commented Jul 15, 2021

I encountered the same problem. An error occurred when using python+skpy to send information. Sendfile kept showing 403. Before that, sendmsg successfully sent data normally.I am sending a local html file.

i'm use mac os system. python 3.8.6 skpy-version 0.10.4

error information:
Traceback (most recent call last):
File "/Users/privatesmac/Downloads/interfaceTest/common/configEmail.py", line 62, in
print(send_report().send())
File "/Users/privatesmac/Downloads/interfaceTest/common/configEmail.py", line 55, in send
ch.sendFile(open(file_path, "rb"), "report.html") # file upload
File "/Users/privatesmac/PycharmProjects/API/venv/lib/python3.8/site-packages/skpy/chat.py", line 241, in sendFile
return self.sendRaw(content=body, messagetype=msgType)
File "/Users/privatesmac/PycharmProjects/API/venv/lib/python3.8/site-packages/skpy/chat.py", line 139, in sendRaw
msgId, arriveTime = self.createRaw(msg)
File "/Users/privatesmac/PycharmProjects/API/venv/lib/python3.8/site-packages/skpy/chat.py", line 75, in createRaw
resp = self.skype.conn("POST", "{0}/users/ME/conversations/{1}/messages"
File "/Users/privatesmac/PycharmProjects/API/venv/lib/python3.8/site-packages/skpy/conn.py", line 237, in call
raise SkypeApiException("{0} response from {1} {2}".format(resp.status_code, method, url), resp)
skpy.core.SkypeApiException: ('403 response from POST https://azwus2-client-s.gateway.messenger.live.com/v1/users/ME/conversations/8:grieved520/messages', <Response [403]>)

@myself521
Copy link

myself521 commented Jul 16, 2021

我遇到了同样的问题。使用python+skpy发送信息时出错。sendfile一直显示403,之前sendmsg正常发送数据成功,我发送的是本地html文件。

我用的是mac os系统。python 3.8.6 skpy 版本 0.10.4

错误信息:
Traceback (最近调用 last):
File "/Users/privatesmac/Downloads/interfaceTest/common/configEmail.py", line 62, in
print(send_report().send())
File "/Users/privatesmac/ Downloads/interfaceTest/common/configEmail.py", line 55, in send
ch.sendFile(open(file_path, "rb"), "report.html") # file upload
File "/Users/privatesmac/PycharmProjects/API/venv /lib/python3.8/site-packages/skpy/chat.py", line 241, in sendFile
return self.sendRaw(content=body, messagetype=msgType)
File "/Users/privatesmac/PycharmProjects/API/venv/lib /python3.8/site-packages/skpy/chat.py”,第 139 行,在 sendRaw
msgId 中,到达时间 = self.createRaw(msg)
文件“/Users/privatesmac/PycharmProjects/API/venv/lib/python3.8/site-packages/skpy/chat.py”,第 75 行,在 createRaw
resp = self.skype.conn("POST", "{0 } /用户/ ME /会话/ {1} /消息”
文件“/Users/privatesmac/PycharmProjects/API/venv/lib/python3.8/site-packages/skpy/conn.py”,线路237,在呼叫
加注SkypeApiException("{0} response from {1} {2}".format(resp.status_code, method, url), resp)
skpy.core.SkypeApiException: ('403 response from POST https://azwus2-client-s .gateway.messenger.live.com/v1/users/ME/conversations/8:grieved520/messages ', <响应 [403]>)

After restart of pycharm,it's work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants