{"action":"created","issue":{"url":"https://api.github.com/repos/kennethreitz/requests/issues/2664","labels_url":"https://api.github.com/repos/kennethreitz/requests/issues/2664/labels{/name}","comments_url":"https://api.github.com/repos/kennethreitz/requests/issues/2664/comments","events_url":"https://api.github.com/repos/kennethreitz/requests/issues/2664/events","html_url":"https://github.com/kennethreitz/requests/issues/2664","id":94306485,"number":2664,"title":"`PUT` to Amazon S3 is failing ","user":{"login":"avinassh","id":640792,"avatar_url":"https://avatars.githubusercontent.com/u/640792?v=3","gravatar_id":"","url":"https://api.github.com/users/avinassh","html_url":"https://github.com/avinassh","followers_url":"https://api.github.com/users/avinassh/followers","following_url":"https://api.github.com/users/avinassh/following{/other_user}","gists_url":"https://api.github.com/users/avinassh/gists{/gist_id}","starred_url":"https://api.github.com/users/avinassh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avinassh/subscriptions","organizations_url":"https://api.github.com/users/avinassh/orgs","repos_url":"https://api.github.com/users/avinassh/repos","events_url":"https://api.github.com/users/avinassh/events{/privacy}","received_events_url":"https://api.github.com/users/avinassh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-10T13:23:10Z","updated_at":"2015-07-10T15:49:14Z","closed_at":null,"body":"I am trying to upload a file to Amazon S3 with Python Requests (Python is v2.7.9 and requests is v2.7). Following the curl command which works perfectly:\r\n\r\n```\r\ncurl --request PUT --upload-file img.png https://mybucket-dev.s3.amazonaws.com/6b89e187-26fa-11e5-a04f-a45e60d45b53?Signature=Ow%3D&Expires=1436595966&AWSAccessKeyId=AQ\r\n```\r\n\r\nHowever when I tried to do same with requests, it fails with 403 with following error: \r\n\r\n```\r\n<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>\r\n```\r\n\r\nHere's what I tried:\r\n```\r\nurl = https://mybucket-dev.s3.amazonaws.com/6b89e187-26fa-11e5-a04f-a45e60d45b53?Signature=Ow%3D&Expires=1436595966&AWSAccessKeyId=AQ\r\nheaders = {'Content-Length': '52369', 'Host': 'mybucket-dev.s3.amazonaws.com', 'Expect': '100-continue', 'Accept': '*/*', 'User-Agent': 'curl/7.37.1'}\r\npayload={'Expires': '1436595966', 'AWSAccessKeyId': 'AQ', 'Signature': 'Ow%3D'}\r\n\r\nrequests.put(url, files={'file': base64_encoded_image})\r\nrequests.put(url, files={'upload_file': base64_encoded_image})\r\nrequests.put(url, files={'file': base64_encoded_image}, headers=headers)\r\nrequests.put(url, files={'file': base64_encoded_image}, headers=headers, data=payload)\r\n```\r\nThey all fail, with same error. Here's curl in verbose mode:\r\n```\r\n* Hostname was NOT found in DNS cache\r\n*   Trying 54.231.168.134...\r\n* Connected to mybucket-dev.s3.amazonaws.com (54.231.168.134) port 443 (#0)\r\n* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA\r\n* Server certificate: *.s3.amazonaws.com\r\n* Server certificate: VeriSign Class 3 Secure Server CA - G3\r\n* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5\r\n> PUT /6b89e187-26fa-11e5-a04f-a45e60d45b53?Signature=Ow%3D&Expires=1436595966&AWSAccessKeyId=AQ HTTP/1.1\r\n> User-Agent: curl/7.37.1\r\n> Host: mybucket-dev.s3.amazonaws.com\r\n> Accept: */*\r\n> Content-Length: 52369\r\n> Expect: 100-continue\r\n>\r\n< HTTP/1.1 100 Continue\r\n* We are completely uploaded and fine\r\n< HTTP/1.1 200 OK\r\n< x-amz-id-2: 5lLCQ3FVrTBg2vkyk44E+MecQJb2OGiloO0+2pKePtxPgZptKECNlUyYN43sl4LBNe9f8idh/cc=\r\n< x-amz-request-id: 636A24D53DEB5215\r\n< Date: Fri, 10 Jul 2015 12:04:44 GMT\r\n< ETag: \"5802130d4320b56a72afe720e2c323a7\"\r\n< Content-Length: 0\r\n* Server AmazonS3 is not blacklisted\r\n< Server: AmazonS3\r\n<\r\n* Connection #0 to host mybucket-dev.s3.amazonaws.com left intact\r\n```"},"comment":{"url":"https://api.github.com/repos/kennethreitz/requests/issues/comments/120441886","html_url":"https://github.com/kennethreitz/requests/issues/2664#issuecomment-120441886","issue_url":"https://api.github.com/repos/kennethreitz/requests/issues/2664","id":120441886,"user":{"login":"Lukasa","id":1382556,"avatar_url":"https://avatars.githubusercontent.com/u/1382556?v=3","gravatar_id":"","url":"https://api.github.com/users/Lukasa","html_url":"https://github.com/Lukasa","followers_url":"https://api.github.com/users/Lukasa/followers","following_url":"https://api.github.com/users/Lukasa/following{/other_user}","gists_url":"https://api.github.com/users/Lukasa/gists{/gist_id}","starred_url":"https://api.github.com/users/Lukasa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lukasa/subscriptions","organizations_url":"https://api.github.com/users/Lukasa/orgs","repos_url":"https://api.github.com/users/Lukasa/repos","events_url":"https://api.github.com/users/Lukasa/events{/privacy}","received_events_url":"https://api.github.com/users/Lukasa/received_events","type":"User","site_admin":false},"created_at":"2015-07-10T15:49:14Z","updated_at":"2015-07-10T15:49:14Z","body":"Well, step 1 is to avoid sending `Expect: 100 Continue`. We don't handle them properly. Please also don't send your own `Content-Length` header: requests will do that for you.\r\n\r\nThe real problem is that I think your upload is going to be multipart/form-encoded, but curl is uploading the file directly. Try: `requests.put(url, data=open('img.png', 'rb'))`"}}