Communicating with a PHP script (and pretending I'm a browser)

Lie Ryan lie.1296 at gmail.com
Thu Nov 13 15:54:38 CET 2014


On 13/11/14 03:57, Larry Martell wrote:
> We were all making this much harder than it is. I ended up doing this:
>
> wp = urllib.request.urlopen('http://php_page/?' + request.POST.urlencode())
> pw = wp.read()

I was about that suggest that actually, just be careful to escape things 
properly. Although I would recommend to pass the parameters as request 
body rather than as query parameters. Going through the web server via 
HTTP is most definitely going to be even more expensive than with pipes, 
but if performance is the least of your concern, then this is probably 
the easiest way to include things between languages.

Yet another methods of mixing languages is to use iframes and to built 
your frontend as HTML with that queries Web APIs with AJAX but this 
relies on the client side to do the inclusion.

As your goal is to eventually port an existing site to Python, I would 
highly recommend against using Django. Django, as a full-featured 
framework, is quite opinionated on how to do things, especially in 
regards to database design. While this is great for a new projects as it 
enforces certain well-tested patterns, this can be a pain when you need 
to use existing tables from the PHP application. Also, if your old 
application database access is written in SQL (i.e. with PHP mysql or 
mysqli driver), it might be less friction to port to SQLAlchemy Core 
rather than jumping straight to a full-fledged ORM, eventually you can 
slowly take the next step to port SQLA Core to SQLA ORM. Or you can mix 
and match Core and ORM with SQLAlchemy (with some care); Django is much 
less flexible about mixing plain SQL with ORM.




More information about the Python-list mailing list