Есть простой код на пайкурле, который посылает пост запрос. На страницу, которая выводит этот пост запрос ( Денвер на локальном компе).
Код php страницы, которая выводит пост запрос
test_curl.php
<?
print_r($_POST);
?>
main.py
import StringIO
import pycurl
def GetPage( curl, url ):
resp = StringIO.StringIO()
curl.setopt(pycurl.WRITEFUNCTION, resp.write)
curl.setopt(pycurl.URL, url )
curl.perform()
the_page = resp.getvalue()
resp.close()
return the_page
def Test():
curl = pycurl.Curl()
aaa = 'SomeParam'
# NOT WORK
curl.setopt(pycurl.POSTFIELDS, r'params%5BsloganText%5D=...because+open+source+matters¶ms%5Bja_screen_width%5D=97¶ms%5Btheme_header%5D=green¶ms%5Btheme_background%5D=lighter¶ms%5Btheme_elements%5D=black¶ms%5BrightCollapsible%5D=1¶ms%5BrightCollapseDefault%5D=show¶ms%5BexcludeModules%5D=38&'+aaa+r'=1')
with open('pycurl_not_work.html','w') as f:
f.write( GetPage( curl, r'http://localhost/test_curl.php' ) )
# WORK
ddd = 'params%5BsloganText%5D=...because+open+source+matters¶ms%5Bja_screen_width%5D=97¶ms%5Btheme_header%5D=green¶ms%5Btheme_background%5D=lighter¶ms%5Btheme_elements%5D=black¶ms%5BrightCollapsible%5D=1¶ms%5BrightCollapseDefault%5D=show¶ms%5BexcludeModules%5D=38&'+aaa+'=1'
curl.setopt(pycurl.POSTFIELDS, ddd)
with open('pycurl_work.html','w') as f:
f.write( GetPage( curl, r'http://localhost/test_curl.php' ) )
if __name__=='__main__':
Test()
В итоге в
pycurl_work.html
Array
(
[params] => Array
(
[sloganText] => ...because open source matters
[ja_screen_width] => 97
[theme_header] => green
[theme_background] => lighter
[theme_elements] => black
[rightCollapsible] => 1
[rightCollapseDefault] => show
[excludeModules] => 38
)
[SomeParam] => 1
)
Один из вариантов pycurl_not_work.html
Array
(
[l_php] => ...because open source matters
[params] => Array
(
[ja_screen_width] => 97
[theme_header] => green
[theme_background] => lighter
[theme_elements] => black
[rightCollapsible] => 1
)
[params_rightCollapseDefauДVцЧю] => 38
[SomeParam] => 1
)
P.S. скорее всего дело в параметрах в виде массива