Showing posts with label python3. Show all posts
Showing posts with label python3. Show all posts

Monday, 14 July 2025

Python mod_WSGI spawn more process

 https://flask.palletsprojects.com/en/stable/deploying/mod_wsgi/

mod_wsgi is a WSGI server integrated with the Apache httpd server. The modern mod_wsgi-express command makes it easy to configure and start the server without needing to write Apache httpd configuration.


$ mod_wsgi-express start-server wsgi.py --processes 4

Tuesday, 17 December 2024

pytho3, python3-saml, xml upgrade library version mismatch 2024

 https://github.com/xmlsec/python-xmlsec/issues/320

!!!!!!!!!!!!!!!!!!!!! be wary when doing docker-compose build --no-cache

“lxml & xmlsec libxml2 library version mismatch” error under uWSGI

It seems like lxml@5.2.1 uses libxml2@2.12.6. However, libxml2@2.12.7 has been released, and python-xmlsec@1.3.14 breaks because of this libxml2 version mismatch (?)

Fix:
in requirements.txt
lxml==4.9.3
xmlsec==1.3.13
python3-saml==1.11.0

Tuesday, 1 October 2024

regex 101, python3 recursively replace single quote inside of double quote

 import re


# Input string

input_str = [{'a': 'b', 'c': "ddd'sss", 'x': "text'with'quotes"}]

input_str = str(input_str)


# Regex pattern to find double quotes and then identify single quotes inside

pattern = r'("([^"]*?)\'([^"]*?)")'


# Replace single quotes with <test> inside double quotes using a lambda function

fixed_output_str = re.sub(pattern, lambda m: m.group(1).replace("'", "<test>"), input_str)


# Displaying the result

print("Output string with single quotes replaced:", fixed_output_str)

python3 sandbox

 https://trinket.io/embed/python3



Wednesday, 18 September 2024

Python change response content to JSON


https://stackoverflow.com/questions/16877422/whats-the-best-way-to-parse-a-json-response-from-the-requests-library

by default python 

response object saves actual resposne in "data"

https://www.geeksforgeeks.org/response-json-python-requests/


you can use response.json() to get the "data" list / object

to get everything:

 import json

import requests

response = requests.get(...)
json_data = json.loads(response.text)

// conver list to json string
json.dumps()

// convert json string to list
json.loads

Thursday, 7 March 2024

python strip string, find index, last index

 https://stackoverflow.com/questions/19454286/python-strip-a-string-from-index

strip string:

>>> mystr = 'foo7bar'
>>> mystr[:mystr.index('7')]
'foo'
>>>

https://stackoverflow.com/questions/9572490/find-index-of-last-occurrence-of-a-substring-in-a-string
last index
string.rindex('bla')
first index
string.index