使用机器人框架上传文件时来自后api的无效图像消息

时间:2017-08-15 15:24:14

标签: python python-2.7 robotframework

我正在尝试使用机器人框架发布请求上传图像文件,但在执行后收到无效的图像错误消息。

代码段

    Create Session      imageupload     http://httpbin.org
    ${headers}=         Create Dictionary     Content-Type=multipart/form-data;boundary=----WebKitFormBoundaryJlIb5JIA0vGUnjmb
    ${my_id}=           Set Variable              ${StudentId}
    ${params} =          Create Dictionary        key_id=Keyinformation   
    ${filepath}=        Get Binary File      c:\User\image.png
    ${file}=             Evaluate     base64.b64encode($filepath)       modules=base64
    ${base86Image}=      Create Dictionary       KeyUploadImage=${file}

    ${URI}=            Set Variable    /my_id/
    ${response}=        Post Request    imageupload     ${URI}   data=${base86Image}    params=${params}        timeout=5
    Log To Console      ${response}

响应:

20170814 15:47:23.854 : DEBUG : post response: {"error":"INVALID_IMAGE"}
20170814 15:47:23.934 : INFO : Post Request using : alias=imageupload       , uri=/my_id/, data=<empty>, headers=None, files={u'file': '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x02N\x00\x00\x01\xba\x08\x06\x00\x00\x00\xfe\xb2\xc9g\x00\x00\x00\x01sRGB\x00\xae\xce\x1c\xe9\x00\x00\x00\x04gAMA\x00\x00\xb1\x8f\x0b\xfca\x05\x00\x00\x00\tpHYs\x00\x00\x0e\xc3\x00\x00\x0e\xc3\x01\xc7o\xa8d\x00\x00\xff\xa5IDATx^\xec\xfdg\x98$\xc7\x95\xae\t\xf2\xef\xfe\xda}fw\xef\xcc\xdc\xdd\x9d\xd9\xee{\xb7u7\x9b\n$\x01Bk\x8d\x02PU@Ak\xad\xb5V$\x14\t\x90\x00\xb5n\xb2)@\x01\x90\x84\x16\x84*\x9d:32D\x86\xcaH\xadK\xeb\x02\x88\xb3\xdfw\xcc\x8f\x87\x85\x87EfdV\x15\xd8\xddD=xa\xeef\xe6\xe6""\xdd\xde037\xff\x98|\xf4\xef\xa3\x7f\x1f\xfd\xfb\xe8\xdfG\xff>\xfa\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|\xb1\x7f\x8fP\\\x1d\xd1\xf7!Yfr\xff\x0b\xc1\xaeIa`@\x89\xaf\x13\xbe\xd3\xf9\xfe\xc1\x86\xf0\xb8\xfd\xf5BeH)\x0e\x0c\xa3\x1c\xacG\xe5\x19\xc5\xc1\xc1\xa6\xf0\xf3\x97\x86\x86\x14?\xdd\xe2B\x94\x87F\x17DipdVB\xdb\x18u\xc70<\xdc<\x81\xf2\x9a\xa1\x04\x8a\xc3\x <truncated>
20170814 15:47:23.961 : INFO : C:\Python27\lib\site-packages\urllib3\connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
20170814 15:47:23.961 : INFO : ${response} = <Response [400]>
20170814 15:47:23.963 : INFO : ${response} = <Response [400]>

0 个答案:

没有答案