2011-12-05 25 views
1

我想上傳並從本網站獲取結果。 http://cello.life.nctu.edu.tw/用python上傳POST文件。去哪裏看?

我試圖

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 

我不知道這裏有什麼問題。有人能指出我嗎? ?謝謝。

btw。 xaa文件看起來像這樣http://pastebin.com/7VK3vvwC

回答

1
Error 500: Internal Server Error 

這是一個服務器錯誤。換句話說,你的代碼沒有問題 - 只是這個頁面出錯了。

+0

嗯,我不知道爲什麼。我嘗試通過網絡瀏覽器使用網頁,它很好。然後我通過網頁瀏覽器訪問網頁,發現「http://cello.life.nctu.edu.tw/cgi/main.cgi」也給我500錯誤。我嘗試在腳本中使用主要網址,但它只是鏈接到主頁面。好像我在腳本中使用了錯誤的URL。你能幫我嗎? –

+1

@Tg當我從瀏覽器直接進入時出現錯誤,但在主頁上使用表單時沒有。我的猜測是腳本寫得不好,不能處理無效輸入,或根本沒有輸入。你確定你的參數是正確的嗎? – Taymon

+0

我不確定。如何檢查這些?關於參數,我從源猜測它,但也許我錯了... –