Я пишу сценарий Python, который пытается загрузить изображения на сервер, и когда я запускаю следующий фрагмент кода, я продолжаю получать ошибку атрибута объекта 'str', у которого нет атрибута 'items', и я не уверен, что я делаю неправильно. Мы будем очень признательны за любую помощь в том, как это написать:
response = requests.request("GET", folder_url, headers=headers, data=payload)
jsonResponse = response.json()
for key, value in jsonResponse.items():
print(key, ":", value)
URL = jsonResponse["presignedUrl"]
processnum = jsonResponse["processId"]
assetupload = requests.request("PUT", URL, headers='Content-Type: image/tiff', data=payload)
Ответ. json следующий:
This is the response.json: {'presignedUrl': 'https://webdamuploads.s3.amazonaws.com/13870_d944a723_4232_4892_bdfd_26dd73edec44.tif?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJBNEEVWEAALCCECQ%2F20200806%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200806T163417Z&X-Amz-SignedHeaders=host&X-Amz-Expires=180&X-Amz-Signature=2856c1a615b88a91fc6c9fee02eae2a051b60b902660d04890d795057dd097e3', 'processId': '200483605'}
Ошибка Traceback:
Traceback (most recent call last):
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\jphelps\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\jphelps\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\jphelps\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "l:\ISG Documentation\Python\individual scripts\upload_asset_to_webdam.py", line 122, in <module>
assetupload = requests.request("PUT", URL, headers='Content-Type:image/tiff', data=payload)
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 516, in request
prep = self.prepare_request(req)
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 449, in prepare_request
p.prepare(
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\models.py", line 315, in prepare
self.prepare_headers(headers)
File "C:\Users\jphelps\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\models.py", line 447, in prepare_headers
for header in headers.items():
AttributeError: 'str' object has no attribute 'items'