I am trying to get the query string in a CGI python script because for some reason the .FieldStorage and .getvalue functions are returning "None". The query is being generated correctly. I checked it in Wireshark and it is correctly produced.
Any ideas on how I can just get the string itself correctly?
I was trying to use os.environ('QUERY_STRING') but that didn't work either.
Josh
I think I figured it out. I need to use the environ variable passed to the application function by mod_wsgi.
Thanks!
Related
I have a Python WebJob living in Azure and I'm trying to pass parameters to it.
I've found documentation saying that I should be able to post the URL and add:?arguments={'arg1', 'arg2'} after it.
However, when I do that and then try to print(sys.argv) in my code, it's only printing the name of the Python file and none of the arguments I pass to it.
How do I get the arguments to pass to my Python code? I am also using a run.cmd in my Azure directory to trigger my Python code if that makes a difference.
UPDATE: So I tested it in another script without the run.cmd and that certainly is the problem. If I just do ?arguments=22 66 it works. So how do I pass parameters when I'm using a run.cmd file?
I figured it out: in the run.cmd file, you need to put "%*" after your script name and it will detect any arguments you passed in the URL.
If anyone is looking to pass named parameter, then add it in the url like:
url?arguments=--arg1 val1 --arg2 "val2" --arg3 0.99
Let say I'm creating an issue in Jira and write the summary and the description. Is it possible to call a python script after these are written that sets the value for another field, depending on the values of the summary and the description?
I know how to create an issue and change fields from a python script using the jira-python module. But I have not find a solution for using a python script while editing/creating the issue manually in Jira. Does anyone have an idea of how I manage that?
I solved the problem by using the Add-on Script runner in Jira. There I created a scripted field in Groovy and called the command prompt and run the python script from there. Here is a simple example of the script
def process = ['cmd', '/c', 'filepathToPython.exe', 'filepathToPythonFile.py'].execute()
process.waitfor()
return p.text
process?.err?.text can be used instead of process.text if one want to see eventual error messages.
Take a look at JIRA webhooks calling a small python based web server?
I'd like to have some information about set of functions (maybe analog of the var_dump() in PHP) which I could use for looking at the content of variables on a server side in a way that they should be printed on server-side somehow during the work process, or on the client-side in the browser's console (chromelogger?).
I was recently involved into a new project, I'm a newbie in Python/Django, so I need to get familiar with the internal logic and hit the ground running.
I'm using extJS on front-end and Django 1.6 on backend.
Thank you!
Just print them and they will appear at dev-server's console:
print some_var
Or, if some_var is a some kind of structure (dict or list), use the pprint module:
import pprint
pprint.pprint(some_var)
I think you are looking for an IDE.. Go for pycharm or eclipse + pydev.
If you are looking to print the variable structure use dir.
If you want to print only the variable content use pretty print(pprint)
If you're trying to diagnose issues on a server or in a production-like environment (i.e., one where you can't just dump into an interactive debugger), might I suggest you use logging?
https://docs.djangoproject.com/en/1.7/topics/logging/
https://docs.python.org/2/library/logging.html (or https://docs.python.org/3/library/logging.html)
You can even go so far as to have an SMTP log handler that will automagically email you log output for certain handlers.
I have a strange problem with converting special characters from HTML. I have a Django project where text is stored HTML-encoded in a MySQL database. This is necessary, because I don't want to lose any formatting of the text.
In a preliminary step I must do operational things on the text like calculating positions, so I need to convert it first and clear it from all HTML-Tags. This is done by BeautifulSoup:
convertedText = str(BeautifulSoup(text.text, convertEntities=BeautifulSoup.HTML_ENTITIES))
convertedText = ''.join(BeautifulSoup(convertedText).findAll(text=True))
By working on my Django-default test-server everything works fine, but when I run it on my production server there are strange behaviors when converting special characters.
An example:
Test server
MySQL-Query gives me: <p>bassverstärker</p>
is correctly converted to: bassverstärker
Production server
MySQL-Query gives me: <p>bassverstärker</p>
This is is wrongly converted to: bassverst\ucc44rker
Somehow the ä is converted into \ucc44 and this results in a wrong character.
My configuration:
Test server:
Django build-in solution (python manage.py runserver)
BeautifulSoup 3.2.1
Python 2.6.5
Ubuntu 2.6.32-43-generic
Production server:
Cherokee 1.2.101
BeautifulSoup 3.2.1
python 2.7.3
Ubuntu 3.2.0-32-generic
Because I don't know at which level the error occurs, I would like to ask if anybody can help me with this. Many thanks in advance.
I found a way to fix this. I didn't know that BeautifulSoup has the builtin method getText(). When converting HTML through:
convertedText = BeautifulSoup(text.text, convertEntities=BeautifulSoup.HTML_ENTITIES).getText()
eveything works fine on both servers. Although this works, it would be interesting to know why both servers are behaving differently when working with the example in the question.
However, thanks to all.
I'm trying to do something similar to placekitten.com, wherein a user can input two strings after the base URL and have those strings alter the output. I'm doing this in Python, and I cannot for the life of me figure out how to grab the URL. In PHP I can do it with query string and $_REQUEST. I can't find a similar method in Python that doesn't rely on CGI.
(I know I could do this with Django, but that's serious overkill for this project.)
This is just by looking at the docs but have you tried it?
cherrypy.request.path_info
The docs say:
The ‘relative path’ portion of the Request-URI. This is relative to the script_name (‘mount point’) of the application which is handling this request.
http://docs.cherrypy.org/stable/refman/_cprequest.html#cherrypy._cprequest.Request.path_info