問題描述
我想發送一個HTTP POST請求的在線BLAST website。我檢查了POST請求,並看到這個:Python的HTTP POST請求格式的表單數據
Request URL:https://p3.theseed.org/services/homology_service
Referrer Policy:no-referrer-when-downgrade
Request Headers
Provisional headers are shown
Accept:application/json
Content-Type:application/x-www-form-urlencoded
Origin:https://www.patricbrc.org
Referer:https://www.patricbrc.org/
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Data
{"method":"HomologyService.blast_fasta_to_database","params":[">test
ATAGCTAACAGCATC","blastn","ref.fna","10",50,0],"version":"1.1","id":"27057295081137034"}:
現在我想做的事這爲幾個序列(因此替換ATAGCTAACAGCATC
)。我熟悉發送這些類型的請求,但我不知道現在怎麼:
- 格式的
form data
,這樣我就可以使用Requests - 我應該在後與
id
做些什麼把它,因爲我不知道這是因爲它對於每一個BLAST工作都是獨一無二的。
代碼
import requests as r
blast_url = 'https://p3.theseed.org/services/homology_service'
data = {"method":"HomologyService.blast_fasta_to_database","params":["%3Etest%0ATAGCTAACAGCATC","blastp","ref.faa","10",'50','0'],"version":"1.1"}
headers = {
'Host': 'p3.theseed.org',
'Accept': 'application/json',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': 'https://www.patricbrc.org/app/BLAST',
'Content-Type': 'application/rqlquery+x-www-form-urlencoded',
'X-Requested-With' : 'XMLHttpRequest'
}
res = r.post(blast_url, headers = headers, params = data).text
print(res)
我沒有在id
填補,但這似乎並沒有因爲錯誤信息的ID填寫是一個問題(這樣看來?自動生成它) 這是錯誤我得到:
{"id":"15004153692662703","error":{"name":"JSONRPCError","code":-32700,"message":"You did not supply any JSON to parse in the POST body."},"version":"1.1"}
如此明顯的表單數據的誤格式化給出了這些親blems,但我不知道我應該怎麼格式化這個(以及這是否會解決這個問題)
井工作天才;)謝謝你這麼多 – CodeNoob