【问题标题】:Upload file to AWS Device Farm将文件上传到 AWS Device Farm
【发布时间】:2018-03-02 13:42:12
【问题描述】:

我正在尝试使用 python + boto3 在设备场中创建上传(上传测试或应用程序)。方法“create_upload”工作正常,因为它返回一个上传 arn 和 url 上传到它。

当我尝试使用请求将文件上传到此 URL 时出现错误:

<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAJV4C3CWPBUMBC3GA</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA256

我的代码:

response = client.create_upload(
  projectArn=df_project,
  name="test.zip",
  type="APPIUM_JAVA_TESTNG_TEST_PACKAGE",
  contentType='application/octet-stream'
)
test_url = response["upload"]["url"]
files = {'upload_file': open('/tmp/test.zip','rb')}
r = requests.post(test_url, files=files, data={})

我也尝试使用 curl 和 requests.post 将文件传递给数据 属性:

r = requests.put(test_url, data=open("/tmp/test.zip", "rb").read())
print(r.text)

cmd = "curl --request PUT --upload-file /tmp/test.zip \""+test_url+"\""
result = subprocess.call(cmd, shell=True)
print(result)

【问题讨论】:

    标签: python-3.x amazon-web-services aws-device-farm


    【解决方案1】:

    我以前在过去的项目中这样做过。这是我如何做到的代码sn-p:

    创建一个新的上传

    #http://boto3.readthedocs.io/en/latest/reference/services/devicefarm.html#DeviceFarm.Client.create_upload
    print('Creating the upload presigned url')
    response = client.create_upload(projectArn=args.projectARN,name=str(args.testPackageZip),type='APPIUM_WEB_JAVA_TESTNG_TEST_PACKAGE')
    #create the s3 bucket to store the upload test suite
    uploadArn = response['upload']['arn']
    preSignedUrl = response['upload']['url']
    print('uploadArn: ' + uploadArn + '\n')
    print('pre-signed url: ' + preSignedUrl + '\n')
    
    #print the status of the upload
    #http://boto3.readthedocs.io/en/latest/reference/services/devicefarm.html#DeviceFarm.Client.get_upload
    status = client.get_upload(arn=uploadArn)
    print("S3 Upload Bucket Status: " + status['upload']['status'] + '\n')
    
    print("Uploading file...")
    #open the file and make payload
    payload = {'file':open(args.testPackageZip,'rb')}
    #try and perform the upload
    r = requests.put(url = preSignedUrl,files = payload)
    #print the response code back
    print(r)
    

    希望有帮助

    【讨论】:

      【解决方案2】:

      我在 AWS Device Farm 工作。当某些请求参数与用于签署 URL 的参数不匹配时,就会出现此问题。我看到这个问题的次数,它与内容类型有关。我建议不要在 CreateUpload 请求中传递它。如果您确实通过了它,那么您还需要在进行 PUT 调用时将其作为请求标头包含在内。

      【讨论】:

        猜你喜欢
        • 2020-07-08
        • 2017-10-03
        • 2016-11-28
        • 2015-10-12
        • 2017-06-26
        • 1970-01-01
        • 1970-01-01
        • 2021-02-22
        • 1970-01-01
        相关资源
        最近更新 更多