简体   繁体   中英

joomla remote login with python?

I'm trying to remotely login to my joomla server but it's not working:

# -*- 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

You can

  1. Create a custom login php page (eg mylogin.php), and from that page you can use Joomla API - JAuthentication to login.
  2. Call this custom php page from your python code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM