post資料至國際FHIR ''Patient''上
http://hapi.fhir.org/resource?serverId=home_r4&pretty=true&resource=Patient
小弟有嘗試照著格式撰寫出現錯誤訊息
程式錄:
def postFHIR11(): #post data to FHIR server RFID
postdata02 = {
"resourceType": "Bundle",
"id": "4ba17d68-022c-478f-ad5a-1fb6b866dda8",
"meta": {
"lastUpdated": "2020-08-10T13:55:05.322+00:00"
},
"type": "searchset",
"total": 0,
"link": [
{
"relation": "self",
"url": "http://hapi.fhir.org/baseR4/Patient"
}
]
}
r = requests.post(url = 'http://hapi.fhir.org/baseR4/Patient', data = json.dumps(postdata02))
print(r.text)
response = json.loads(r.text)
print('狀態碼,r.status_code)
錯誤訊息
{
"resourceType": "OperationOutcome",
"text": {
"status": "generated",
"div": "<div xmlns="http://www.w3.org/1999/xhtml">Operation Outcome<table border="0"><td style="font-weight: bold;">ERROR[]No Content-Type header was provided in the request. This is required for "CREATE" operation\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t"
},
"issue": [ {
"severity": "error",
"code": "processing",
"diagnostics": "No Content-Type header was provided in the request. This is required for "CREATE" operation"
} ]
}
狀態 400
請問是什麼原因造成的
錯誤訊息是說No Content-Type header was provided in the request
那就在 header 裡提供 Content-Type 參數
原
r = requests.post(url = 'http://hapi.fhir.org/baseR4/Patient', data = json.dumps(postdata02))
改成
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
r = requests.post(url = 'http://hapi.fhir.org/baseR4/Patient', data = json.dumps(postdata02), headers=headers)
試試看
謝謝前輩經驗點數+1
結果如何?有解決嗎?
可以順利上傳 但有一個小問題 我嘗試添加參數
def postFHIR11(): #post data to FHIR server RFID
postdata02 = {
"resourceType": "Patient",
"id": "4ba17d68-022c-478f-ad5a-1fb6b866dda8",
"meta": {
"lastUpdated": "2020-08-10T13:55:05.322+00:00"
},
"metas": {
"text": 'aaa'
"metas": {
"text": 'aaa'
是我要隨便添加的文字
再上傳一次的話
一樣如上圖沒有添加文字