웹에 검색 한 후 파일을 업로드하는 API 요청을 보내면 'payload'가 전송해야하는 추가 매개 변수가있는 곳이 생겼습니다. 와 '파일'I 업로드 할 파일의 경로입니다 :파이썬 요청 - 추가 파라메타가있는 POST 파일
def sendAPIRequest2(self, env, object, method, params, files):
apiPath = "/api/secure/jsonws"
headers = {'content-type': 'multipart/form-data'}
url = env + apiPath + object
payload = {
"method": method,
"params": params,
"jsonrpc": "2.0"
}
data = json.dumps(payload)
myFile = {'file': open(files,'rb')}
try:
r = requests.post(url, files=myFile, data=data, headers=headers,
auth=HTTPBasicAuth(self.user, self.password), verify=False)
print r.text
resjson = json.loads(r.text)
except:
print "no Valid JSON has returned from"+object+" API"
sys.exit(1)
return resjson
내가 얻을 : 내가 잘못 뭐하는 거지
ValueError: Data must not be a string.
?
은 전체 오류 메시지 (Traceback)를 문제의 텍스트로 표시합니다 (스크린 샷이 아님). 다른 유용한 정보가 있습니다. 즉. 어느 선이 문제가되는지를 보여줍니다. – furas
가능한 중복 된 [ValueError : 데이터는 문자열이 아니어야합니다] (https://stackoverflow.com/questions/27553082/valueerror-data-must-not-be-a-string) –
나에게 중복 된 것처럼 보이지만 그 이유는 무엇입니까? json.loads (r.text) 대신 r.json()을 사용하지 않습니까? –