question

Zhi Kang Shao avatar image
Zhi Kang Shao asked

Trouble uploading a server build via Python

I'm trying to upload a server build to a URL retrieved via GetServerBuildUploadUrl(). The retrieved URL seems valid, but I'm having issues uploading to it. I've written the following Python script to attempt this:

http://pastebin.com/MXCfzUms

The retrieved URL, stored in the script as 'upload_url', is for example:

https://gamebuild-playfab-live.s3-us-west-2.amazonaws.com/####/Build001.zip?AWSAccessKeyId=ASIAJH2XGARXIQSQPZTA&Expires=1487168042&x-amz-security-token=FQoDYXdzEBYaDIbC0v9iDLrvtydDUSK3AwJX%2BdRfowazC13bYm%2F22ZZ8E3h6pdKMOGIx598ks%2FrY%2Bcgb8qFz5SLUBchpCjBaewir%2BVzigNkTXTJzPmdWfdk0ABLfEOaJW4MVSQw9TdkF8CuMX4k4iKFA2uwrHJfJGPaoIPUX64AkrnnctLDrr9%2BMMbz2gHP5Qr5MR2Rio12WgIrefraR3UztaLQWBaqVOgaFbTvzmuX7bhtKjwZ1J%2F%2FXXY5rB8hCHd2isDpy0e4QiE5Ftc95Q1XyvZZ1Mo9l0xn2ShySUzc8JJeN0X%2FtmYLAWk7dSjXLRH4X0m%2BDKsp5I%2FJay6YxHFtnZnuI174g%2BrjmHgd2hhEYUMXeervRx60dAeHYhzfP51KvPbEoCm5tNc3f18gC8Fx3MVIz3sifoSADFcVMQjd8bxAgQn0Gukf%2BT9%2BRbeoboJbneDgtxmQEdTxMXFQyacupeS6%2ByI3tmlGNDN4oBEWsSMb%2FR0NlibZBHVWIuXDzL2E5Y3s5P%2FbKhw2yITSYB46hsrZ1tP9HlxI1zLjEc6y9TGrdjt5GAbRtom%2FbwIts674PM3kkTKfM6z4baFH9Hud9MMOsVzJf2BiD2cV95GMo9JGRxQU%3D&Signature=pC%2FKKsQ3Jo1k2amzIAWUdFSdmgg%3D

with #### being the title ID of our game on PlayFab. I'm trying to upload a file directly to that URL, assuming that any authentication is already handled via the URL. Is that assumption correct?

I'm getting a 403 from Amazon with the error message 'The request signature we calculated does not match the signature you provided. Check your key and signing method.'

I should note that I'm not that familiar with HTTP requests nor Python, so I'm hoping anyone can point out something I'm blatantly doing wrong. :) We're using Jenkins, so if there is a more recommended way to automate the uploading of server builds from Jenkins I'd be happy to hear it too.

Custom Game Servers
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Zhi Kang Shao avatar image
Zhi Kang Shao answered

Although that gave the same 403 error, it did put me in the right direction. I wasn't using the right syntax for specifying the upload type (in the body instead of the header). This next snippet worked:

headers = {
	'Content-Type': 'application/x-zip-compressed'
}
with open('TestFile.zip', 'rb') as data:
	r = put(upload_url, data=data, headers=headers)

Thanks for the help!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

We use pre-signed URLs for S3 uploads, for security. Unfortunately, the requests post method in your code is attempting to do a multi-part file upload against that, which isn't going to work. Could you try this?

with open('TestFile.zip', 'rb') as data:
    requests.put(upload_url, data=data)
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.