Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Multipart request question #380

Closed
mgp25 opened this issue Apr 24, 2018 · 2 comments
Closed

Multipart request question #380

mgp25 opened this issue Apr 24, 2018 · 2 comments

Comments

@mgp25
Copy link

mgp25 commented Apr 24, 2018

Hello,

I am trying to migrate one of my libraries to use hyper, and I am facing some issues. I think I am doing it right, but maybe I am wrong, and thats why I am opening this issue. If you could point me if what I have done is right or not.

The request I want to do:

:method: POST
:path: /groupMessaging/v1/messageGroups/~xxxE837DyyyB2E5C.7F6zzz27ED000ECA/messages
:authority: es-gmsg.np.community.playstation.net
:scheme: https
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0
accept: */*
accept-language: es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3
accept-encoding: gzip, deflate, br
content-type: multipart/mixed; boundary="---------------------------26061"
authorization: Bearer 15e000c-36p0-400a-8b53-e94e0009745f
content-length: 204
origin: https://my.playstation.com
dnt: 1


-----------------------------26061
Content-Type: application/json; charset=utf-8
Content-Description: message

{"message":{"messageKind":1,"body":"que tal?"}}
-----------------------------26061--

The code I have done:

        boundary = "---------------------------"+str(random.sample(range(10000, 99999), 1)[0])

        header = {
            'origin': 'https://my.playstation.com',
            'Authorization': 'Bearer ' + self.oauth,
            'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0',
            'Content-Type': 'multipart/mixed; boundary='+boundary,
            'accept-encoding': 'gzip, deflate, br',
            'accept': '*/*',
            'dnt': '1',

        }

        message_body = {
            "message": {
                "messageKind": 1,
                "body": message_text
            }
        }

        message = "\n"
        message += boundary+"\n"
        message += "Content-Type: application/json; charset=utf-8\n"
        message += "Content-Description: message\n"
        message += "\n"
        message += json.dumps(message_body) + "\n"
        message += boundary + "--\n"


        conn = HTTP20Connection("es-gmsg.np.community.playstation.net:443")
        request = conn.request('POST', "/groupMessaging/v1/messageGroups/"+thread_id+"/messages", headers=header, body=message)
        response = conn.get_response(request)
        print(response.read())

I have the feeling it has to be something related with the body, but I don't know.

Thanks,

Regards

@sigmavirus24
Copy link
Contributor

I'm not certain this is the best place for this question. You're likely to get better support on StackOverflow.

That said, I wonder if the leading \n is correct and I think that multipart/form-data expects line endings like \r\n

@mgp25
Copy link
Author

mgp25 commented Apr 25, 2018

Hello @sigmavirus24,

Yes, i forgot to add the \r\n instead of the \n. My question was wether the body was in the appropiate format to be used with hyper.

I'll follow your suggestion and ask in StackOverflow.

Thanks for the response.

Regards.

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

No branches or pull requests

2 participants