Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80688 > unrolled thread
| Started by | Lie Ryan <lie.1296@gmail.com> |
|---|---|
| First post | 2014-11-14 01:54 +1100 |
| Last post | 2014-11-13 14:41 -0500 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Communicating with a PHP script (and pretending I'm a browser) Lie Ryan <lie.1296@gmail.com> - 2014-11-14 01:54 +1100
Re: Communicating with a PHP script (and pretending I'm a browser) Roy Smith <roy@panix.com> - 2014-11-13 14:41 -0500
| From | Lie Ryan <lie.1296@gmail.com> |
|---|---|
| Date | 2014-11-14 01:54 +1100 |
| Subject | Re: Communicating with a PHP script (and pretending I'm a browser) |
| Message-ID | <mailman.15778.1415890500.18130.python-list@python.org> |
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.
[toc] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2014-11-13 14:41 -0500 |
| Message-ID | <roy-972F3A.14411613112014@news.panix.com> |
| In reply to | #80688 |
In article <mailman.15778.1415890500.18130.python-list@python.org>,
Lie Ryan <lie.1296@gmail.com> wrote:
> 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()
You can do this if you want, but it's much easier to use requests
library (http://docs.python-requests.org/). Compared to using the raw
urllib stuff, requests makes it trivial to deal with argument encoding,
cookie management, and a zillion other little details which will drive
you crazy if you try to roll your own with urllib.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web