python中使用POST上传文件。去哪里看?

发布于 2024-12-19 15:42:33 字数 1751 浏览 3 评论 0原文

我想从这个网站上传并获取结果。 http://cello.life.nctu.edu.tw/

我尝试过

from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2

register_openers()

params = ({"file": open("xaa", "r"),
       "seqtype": "prot",
       "species": "eu"})
datagen, headers = multipart_encode(params)

request = urllib2.Request("http://cello.life.nctu.edu.tw/cgi/main.cgi", datagen, headers)
print urllib2.urlopen(request).read()

,但得到了一个错误

  Traceback (most recent call last):
  File "client.py", line 9, in <module>
    a = opener.open("http://cello.life.nctu.edu.tw/cgi/main.cgi", params)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 400, in open
    response = meth(req, response)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 513, in http_response
    'http', request, response, code, msg, hdrs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 438, in error
    return self._call_chain(*args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 521, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error

我不知道这里出了什么问题。有人可以指点我一下吗。 ?谢谢。

顺便提一句。 xaa 文件如下所示 http://pastebin.com/7VK3vvwC

I want to upload and get the result from this website. http://cello.life.nctu.edu.tw/

I tried

from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import urllib2

register_openers()

params = ({"file": open("xaa", "r"),
       "seqtype": "prot",
       "species": "eu"})
datagen, headers = multipart_encode(params)

request = urllib2.Request("http://cello.life.nctu.edu.tw/cgi/main.cgi", datagen, headers)
print urllib2.urlopen(request).read()

but I got an error

  Traceback (most recent call last):
  File "client.py", line 9, in <module>
    a = opener.open("http://cello.life.nctu.edu.tw/cgi/main.cgi", params)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 400, in open
    response = meth(req, response)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 513, in http_response
    'http', request, response, code, msg, hdrs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 438, in error
    return self._call_chain(*args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 521, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error

I have no idea what is wrong here. Could someone point me out. ? Thanks.

btw. The xaa file looks like this http://pastebin.com/7VK3vvwC

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁客 2024-12-26 15:42:33
Error 500: Internal Server Error

这是服务器错误。换句话说,您的代码没有任何问题 - 只是此页面出现错误。

Error 500: Internal Server Error

This is a server error. In other words there is nothing wrong with your code - it's just this page errors out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文