我正在开发一个我正在上课的工作流程。我正在尝试利用tool,这需要我上传两个文件并提供电子邮件和工作名称。
我已尝试过本网站的许多建议并阅读documentation请求,但似乎没有任何效果。
这是我的(杂乱)代码:
import requests, sys, urllib3, json, os
START_URL = 'https://bmm.crick.ac.uk/~svc-bmm-swarmdock/submit.cgi'
EMAIL = 'someAddress@domain.com'
if len(sys.argv) != 3:
print('Usage: -a receptor -a ligand')
sys.exit(1)
'''
with open('./Swarm Dock/pdb/1asu.pdb') as rec_file:
rec_contents = rec_file.read()
with open('./Swarm Dock/pdb/2msi.pdb') as lig_file:
lig_contents = lig_file.read()
'''
print('cwd: {}'.format(os.getcwd()))
form_data = {
'formSubmitBut': 'Submit New Job',
'jobname': 'test1',
'email': EMAIL
} #, 'receptorfile': rec_contents, 'ligandfile': lig_contents}
files = {
'receptorfile': (open('./Swarm Dock/pdb/1ASU.pdb', 'rb'), 'fakepath/1asu.pdb'), #'receptorfile': ('1ASU',open('./Swarm Dock/pdb/1ASU.pdb', 'rb'), 'plain/text'),
'ligandfile': (open('./Swarm Dock/pdb/2MSI.pdb', 'rb'), 'fakepath/2msi.pdb')
}
response = requests.post(START_URL, files=files, data=form_data)
print(response.content)
这是输出:
b'<!DOCTYPE html>\n<html>\n<head>\n <meta name="robots" content="noarchive">\n <meta name="description" content="SwarmDock Server">\n <meta name="keywords" content ="SwarmDock, The Francis Crick Institute, Mieczyslaw Torchala, Iain Moal, Raphael Chaleil, Juan Fernandez-Recio, Paul Bates">\n <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link href=\'https://fonts.googleapis.com/css?family=Crafty+Girls\' rel=\'stylesheet\' type=\'text/css\'><link rel="stylesheet" type="text/css" href="https://bmm.crick.ac.uk/~svc-bmm-swarmdock/sds.css" /><title>SwarmDock Server</title>\n <script type="text/javascript">\n function validateForm() {\n var ea = document.forms["sdsForm"]["email"].value;\n var jn = document.forms["sdsForm"]["jobname"].value;\n var rf = document.forms["sdsForm"]["receptorfile"].value;\n var lf = document.forms["sdsForm"]["ligandfile"].value;\n var rm = document.forms["sdsForm"]["recnm"].value;\n var lm = document.forms["sdsForm"]["lignm"].value;\n\t var eapattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+.[a-zA-Z]{2,6}/;\n\t var jnpattern = /^[a-zA-Z0-9 ]/;\n if (ea.length < 7) {\n document.getElementById(\'jserrormsg\').innerHTML = \'<div class="message">Error: Email address should be at least seven characters long</div><br />\';\n return (false);\n }\n if (!ea.match(eapattern)) {\n document.getElementById(\'jserrormsg\').innerHTML = \'<div class="message">Error: Email address is not correct</div><br />\';\n return (false);\n }\n if (jn.length < 3) {\n document.getElementById(\'jserrormsg\').innerHTML = \'<div class="message">Error: Job name should be at least three characters long</div><br />\';\n return (false);\n }\n if (!jn.match(jnpattern)) {\n document.getElementById(\'jserrormsg\').innerHTML = \'<div class="message">Error: Job name contains characters which are not allowed</div><br />\';\n return (false);\n }\n if (rf.length < 1) {\n document.getElementById(\'jserrormsg\').innerHTML = \'<div class="message">Error: Receptor file is empty or not chosen</div><br />\';\n return (false);\n }\n if (lf.length < 1) {\n document.getElementById(\'jserrormsg\').innerHTML = \'<div class="message">Error: Ligand file is empty or not chosen</div><br />\';\n return (false);\n }\n if ((rm.length < 1) || (rm.length > 25)) {\n document.getElementById(\'jserrormsg\').innerHTML = \'<div class="message">Error: Number of normal modes for receptor has to between 1 and 25</div><br />\';\n return (false);\n }\n if ((lm.length < 1) || (lm.length > 25)) {\n document.getElementById(\'jserrormsg\').innerHTML = \'<div class="message">Error: Number of normal modes for ligand has to between 1 and 25</div><br />\';\n return (false);\n }\n return (true);\n }\n function isblind(type) {\n if (type == \'blind\') {\n document.sdsForm.formSubmitBut.value = \'Submit new job\';\n } else {\n document.sdsForm.formSubmitBut.value = \'Choose residues\';\n }\n return (true);\n }\n function confirmChosenFile(type) {\n\tif (type == \'rec\') {\n\t document.getElementById(\'recfileconfirm\').innerHTML = document.sdsForm.receptorfile.value;\n }\n if (type == \'lig\') {\n\t document.getElementById(\'ligfileconfirm\').innerHTML = document.sdsForm.ligandfile.value;\n }\n }\n </script>\n<script src="https://bmm.crick.ac.uk/~svc-bmm-swarmdock/jmol-latest/JSmol.min.js" type="text/javascript"></script>\n <script type="text/javascript">\n var myJmol1, myJmol2, myJmol3, myJmol4, myJmol5, myJmol6;\n var Info = {\n width: 600,\n height: 600,\n color: "white",\n use: "JAVA HTML5",\n j2sPath: "jmol-latest/j2s",\n\tjarPath: "jmol-latest/java",\n disableJ2SLoadMonitor: true,\n disableInitialConsole: true,\n allowJavaScript: true\n }; \n </script>\n\n</head>\n\n<body>\n <div id="container">\n <div id="header">\n <h1>SwarmDock Server</h1>\n <h2>webservice for generating 3D structures of protein-protein complexes</h2>\n <br />\n <p id="menu"><a href="https://bmm.crick.ac.uk/~svc-bmm-swarmdock/index.html">Introduction</a> | <a href="https://bmm.crick.ac.uk/~svc-bmm-swarmdock/references.html">References</a> | <a href="https://bmm.crick.ac.uk/~svc-bmm-swarmdock/algorithm.html">Algorithm</a> | <a href="https://bmm.crick.ac.uk/~svc-bmm-swarmdock/submit.cgi">Submit new job</a> | <a href="https://bmm.crick.ac.uk/~svc-bmm-swarmdock/checkStatus.cgi">Check job status</a></p>\n <br />\n </div>\n <div id="content">\n<h2>Submit new job</h2>\n<form action="submit.cgi" name="sdsForm" method="post" enctype="multipart/form-data" onSubmit="return validateForm()">\n Prepare two PDB files: the first one with ligand, the second one with receptor. <b>Files must have TER after each chain (also after last one). Only standard residues are allowed. Files with missing residues or missing atoms other than H are generally not allowed. However, we will try to model missing residues for you, as well as exchange nonstandard residues to standard ones.</b> If you do not know any residues belonging to receptor\'s or ligand\'s binding site, choose Blind docking. For docking with restraints we offer an additional interface prediction tool. Next click Submit button. When the job is completed, you will get an email message with further instructions. <br /><br />\n <output id="jserrormsg"></output>\n <label>Email address:</label><input name="email" type="text" class="w300" value="ser499webscraper@gmail.com" /><br />\n <label>Job name:</label><input name="jobname" type="text" class="w300" value="test1" /><br /><br />\n <label>Receptor PDB file:</label><input name="receptorfile" type="file" class="file" onChange="document.sdsForm.blind[1].disabled=false;confirmChosenFile(\'rec\');" /><br />Chosen receptor file: <b id="recfileconfirm"></b><br /><label>Number of normal modes:</label><select name="recnm"><option>1</option><option>2</option><option>3</option><option>4</option><option selected="selected">5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option></select><br /><br />\n <label>Ligand PDB file:</label><input name="ligandfile" type="file" class="file" onChange="confirmChosenFile(\'lig\');" /><br />Chosen ligand file: <b id="ligfileconfirm"></b><br /><label>Number of normal modes:</label><select name="lignm"><option>1</option><option>2</option><option>3</option><option>4</option><option selected="selected">5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>25</option></select><br /><br />\n <label>Docking type:</label><input type="radio" name="blind" value="1" class="radio" checked="checked" onClick="isblind(\'blind\')"/>Full blind<input type="radio" name="blind" value="0" class="radio" disabled="disabled" onClick="isblind(\'none\')" />I want to choose interface residues<br />\n <br />Please note that computations may take <b>up to few days</b>. Execution time depends not only on the size of the structure, but also on computational resources available. If you don\'t receive a response from the server <b>within one week</b> please inform us - we will check the status of your job. The solutions will be deleted one week after you receive the results.<br /><br />\n<input class="submitbutton" name="formSubmitBut" type="submit" value="Submit new job" /><br />\n</form>\n </div>\n <div id="footer">\n\t Version: 15.04.01<br /><br />\n <a href="https://www.crick.ac.uk/"><img src="https://bmm.crick.ac.uk/~svc-bmm-swarmdock/crick.jpg" alt="" /></a>\n </div>\n </div>\n</body>\n</html>\n'
正如您在输出中看到的那样,正确填写了作业名称和电子邮件字段。我不明白为什么输出id =&#39; jserrormsg&#39;,id =&#39; ligfileconfirm&#39;和id =&#39; recfileconfirm&#39;没有显示任何值。似乎表格由于某种原因没有提交。
我试过了:
form_data = {
'formSubmitBut': 'Submit New Job',
'jobname': 'test1',
'email': EMAIL }
files = {
'receptorfile': open('./Swarm Dock/pdb/1ASU.pdb', 'rb'),
'ligandfile': open('./Swarm Dock/pdb/2MSI.pdb', 'rb')
}
response = requests.post(START_URL, files=files, data=form_data)
和
form_data = {
'formSubmitBut': 'Submit New Job',
'jobname': 'test1',
'email': EMAIL
}
files = {
'receptorfile': ('1asu.pdb', open('./Swarm Dock/pdb/1ASU.pdb', 'rb'), 'application/vnd.palm', {'Expires': '0'}),
'ligandfile': ('2msi.pdb', open('./Swarm Dock/pdb/2MSI.pdb', 'rb'), 'application/vnd.palm', {'Expires': '0'})
}
response = requests.post(START_URL, files=files, data=form_data)
print(response.content)
和
import requests, sys, urllib3, json, os
from requests_toolbelt.multipart.encoder import MultipartEncoder
multipart_data = MultipartEncoder(
fields={
'receptorfile': ('1asu.pdb', open('./Swarm Dock/pdb/1ASU.pdb', 'rb'), 'text/plain', {'Expires': '0'}),
'ligandfile': ('2msi.pdb', open('./Swarm Dock/pdb/2MSI.pdb', 'rb'), 'text/plain', {'Expires': '0'}),
'jobname': 'test1',
'email': EMAIL
}
)
response = requests.post(START_URL, data=multipart_data, headers={'Content-Type': multipart_data.content_type})
print('Status Code: {}'.format(response.status_code))
print(response.content)
响应代码为200,输出与上述相同。