Joseph Straceski Joseph Straceski - 1 year ago 85
Python Question

How to get a uuid with python requests

I am attempting to log into a web page using the python requests module but the Post data on the website that I want to log into includes a uuid tag.

pass: ********
user: ********
uuid: ********

I have thoroughly searched for any mention of this anywhere in most requests documentation. Is this simply out of the capabilities of the program or is it something that I am overlooking.

This is the code I am using.

import requests

url = ''

with requests.Session() as c:
values = {'pass': 'passsword', 'user': 'username'}
response =, data=values)
print response

Answer Source

You can parse it from the source:

In [29]: from bs4 import BeautifulSoup

In [30]: import re

In [31]: patt = re.compile("document.cplogin.uuid.value=\"(.*?)\"")

In [32]: with requests.Session() as s:
   ....:         page = s.get('').content
   ....:         soup = BeautifulSoup(page, "html.parser")
   ....:         script = soup.find("script", language="javascript1.1")
   ....:         uuid =

In [33]: uuid
Out[33]: u'ff3e7ddd-0823-4f44-a003-0e68a9321e08'

If you look at the source of the login page, inside the script with the attribute language="javascript1.1", you can see the uuid:

function login()

So just pass that along with the rest of the form data when you post.

The post url also seems to be, so:

from bs4 import BeautifulSoup
import re

patt = re.compile("document.cplogin.uuid.value=\"(.*?)\"")
data = {"user":"uname", "pass":"passw"}
post = ""

with requests.Session() as s:
    page = s.get('')
    soup = BeautifulSoup(page.content, "html.parser")
    script = soup.find("script", language="javascript1.1")
    uuid =
    data["uuid"] = uuid
    resp =, data=data)