0
Je suis en train de se connecter à distance à mon serveur joomla mais il ne fonctionne pas:Connexion à distance joomla avec python?
# -*- coding: utf-8 -*-
import cookielib
import urllib
import urllib2
# Store the cookies and create an opener that will hold them
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
# Add our headers
opener.addheaders = [('User-agent', 'RedditTesting')]
# Install our opener (note that this changes the global opener to the one
# we just made, but you can also just call opener.open() if you want)
urllib2.install_opener(opener)
# The action/ target from the form
authentication_url = 'http://www.myjoomla.se/index.php'
# Input parameters we are going to send
payload = {
'username': 'username',
'password': 'xxxyyyzzz',
'form-id' : 'login-form',
'task' : 'user.login',
'option' : 'com_users',
'silent' : 'true',
'return' : 'L2luZGV4LnBocA==',
'remember' : 'yes',
'cb8bb294ab888a933862ab988c196a0c': '1',
'task' : 'user.login'
}
# Use urllib to encode the payload
data = urllib.urlencode(payload)
# Build our Request object (supplying 'data' makes it a POST)
req = urllib2.Request(authentication_url, data)
# Make the request and read the response
resp = urllib2.urlopen(req)
contents = resp.read()
print contents
contents = resp.read()
# The action/ target from the form
authentication_url = 'http://www.myjoomla.se/phpBB3/posting.php?mode=reply&f=5&t=40344'
# Use urllib to encode the payload
data = urllib.urlencode({'message':'TEST'.encode('latin-1') })
# Build our Request object (supplying 'data' makes it a POST)
req = urllib2.Request(authentication_url, data)
# Make the request and read the response
resp = urllib2.urlopen(req)
contents = resp.read()
#print contents