#!/usr/bin/python
import pycurl
import re
import StringIO
#CONSTANTS
URL = "http://www.imagehost.org"
FILE = "/datos/poop1.jpg"
POST_DATA = [("a", "upload"), ("file[]", (pycurl.FORM_FILE, FILE))]
buffer = StringIO.StringIO()
c = pycurl.Curl()
c.setopt(c.URL, URL)
c.setopt(c.POST, 1)
c.setopt(c.POSTFIELDS, POST_DATA)
##c.setopt(c.HTTPPOST, POST_DATA)
c.setopt(c.USERAGENT,'Curl')
c.setopt(c.WRITEFUNCTION, buffer.write)
c.setopt(pycurl.VERBOSE, 1)
c.perform()
c.close()
#c.setopt(c.PROXY, proxyHostAndPort)
#c.setopt(c.PROXYUSERPWD, proxyAuthentication)
parse = buffer.getvalue()
pattern = re.compile('/<td nowrap="nowrap">(.+)<\/td>\s*<td class="link"><input.+value="([^"]+)" \/><\/td>/i')
result = re.search(pattern, parse)
print result
問題は投稿の仕方にあります。ファイルを送信しているときにpython curlに問題がある
c.setopt(c.POSTFIELDS、POST_DATA)はリストを受け入れないため、リストを追加する代わりに何をすればよいですか?
とc.setopt(c.HTTPPOST、POST_DATA)が下がる:
Traceback (most recent call last):
File "pymage", line 26, in <module>
c.perform() pycurl.error: (26, 'failed creating formpost data')
更新:
-------------------- --------- 15758382912173403811539561297 \ r \ n内容 - 配置:フォームデータ。名前= "a" \ r \ n \ r \ nアップロード\ r \ n ----------------------------- 15758382912173403811539561297 \ r \ nContent-Disposition:フォームデータ。 name = "file []";ファイル名= "Datos_Pegados_0a17.jpg" \ r \ n内容タイプ:image/jpeg \ r \ n \ r \ nØØÿà
これは改ざんデータを使用して取得したものです。 postfieldの
興味深い部分:
フォームデータ。名前= "a" \ r \ n \ r \ nアップロード\ r \ n
フォームデータ。
だから、POST_DATAは 'a = upload & file [] = FILE'にする必要がありますか?
アップデート2:
コードです<form method="post" action="/" enctype="multipart/form-data" onsubmit="javascript:Upload(); return true;">
<input type="hidden" name="a" value="upload" />
<td class="left">File:</td>
td class="right"><input name="file[]" type="file" size="20" /></td>
...
今では、フォーム・データ構造を働いているが、それは私が
c.setopt(Cを信じて、ファイルをアップロードしていません。 POSTFIELDS、 '= &ファイルをアップロード[] =/datos/poop1.jpg')
私はこの取得しています:
0123を* About to connect() to www.imagehost.org port 80 (#0)
* Trying 74.63.87.74... * connected
* Connected to www.imagehost.org (74.63.87.74) port 80 (#0)
> POST/HTTP/1.1
User-Agent: Curl
Host: www.imagehost.org
Accept: */*
Content-Length: 32
Content-Type: application/x-www-form-urlencoded
< HTTP/1.1 200 OK
< Transfer-Encoding: chunked
< Date: Wed, 25 Mar 2009 06:53:49 GMT
< Content-Type: text/html
< Server: nginx/0.7.11
< Set-Cookie: userhash=7c09b97cc70c8c133c850a3e744b416e; expires=Thu, 25-Mar-2010 06:53:49 GMT; path=/; domain=.imagehost.org; httponly
<
* Connection #0 to host www.imagehost.org left intact
* Closing connection #0
ケアはもう少し具体的ですか?あなたはどんなエラーを出していますか? –
私はデータを挿入するために使用している方法が間違っていると思います。 –
あなたが何をしようとしているのかを記述すると、より良い回答を得ることができます。 – vezult