user272426 user272426 - 5 months ago 28
Python Question

Python post to remote host

Hi I want to write robot to register in toefl test , I send request to remote web site as:

from django.http import HttpResponse

import requests

from bs4 import BeautifulSoup
from django.middleware import csrf

def index(request):
session = requests.Session()
page = session.get('')

if request.method == 'POST':
url = ''
data = {
'password': request.POST.get('password', ''),
'username': request.POST.get('username', ''),
'org.apache.struts.taglib.html.TOKEN': request.POST.get('org.apache.struts.taglib.html.TOKEN', '')

page =, data=data)

return HttpResponse(request,page.text)

My post request is not same as post request made by toefl original web site and instead of login shows error as : We are sorry, our servers are currently busy. Please wait a few minutes and retry your request.

what is the problem? someone in other corporation did this without error


you should make sure that you enter cookies correctly like:

def index(request):

response = HttpResponse()
if 'JSESSIONID' in request.COOKIES:
    session = requests.Session()
    page = session.get('')
    cookie = page.cookies
    for c in cookie:
        response.set_cookie(, c.value)

iud = '1'
if request.method == 'POST':
    url = ''
    iud = '2'
    page =, data=data, cookies=request.COOKIES)
    cookie = page.cookies

response.write(pageReader(request, page.text, iud))
return response