问题描述
我想发送一个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