Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80531

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

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <glicerinu@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'django.': 0.05; 'output': 0.05; 'variables': 0.07; 'string': 0.09; 'back.': 0.09; 'subject:script': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'django': 0.11; 'cmd': 0.16; 'code?': 0.16; 'expects': 0.16; 'subject:PHP': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'app': 0.19; 'passing': 0.19; "skip:' 30": 0.19; 'later': 0.20; 'code,': 0.22; 'input': 0.22; 'cc:addr:python.org': 0.22; 'environment': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'script': 0.25; 'first,': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "skip:' 10": 0.31; 'extract': 0.31; 'larry': 0.31; 'marc': 0.31; 'view.': 0.31; 'subject: (': 0.35; 'subject:with': 0.35; 'something': 0.35; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'html,': 0.36; 'templates': 0.36; 'nov': 0.38; 'needed': 0.38; 'issue': 0.38; 'pm,': 0.38; 'subject:skip:C 10': 0.61; 'information': 0.63; 'to:addr:gmail.com': 0.65; 'heavy': 0.81; 'curl': 0.84; 'guideline': 0.84; 'lifting': 0.84; 'route': 0.84; 'state.': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=+h0/CPghBT9/Vecqm5jneFRC8EHtRCqrUj0F94Vwl1A=; b=B8r68VooxkGVb1jV1+7qvg0I9wlQvZES5QHRTdo2ahl4hWI/186BjeeHTiYZPBkp4d cqliIscIGlSuQyMVdiWu4zcdMaACnQE7UDLf862jBJ2uDOFc95iotcEIKMVn4T4Hl+gv +PkFY/WZJxYAb8pyoeIm7WTS6wr4idqSdO1ZDiPhCTdaV5yJoOVAz++4xljcIkuzbzeA UZedO3IGV9dzJwz1aHROefcu6F5eJFSf1A5+kIql3yyNklLFQ16DOjAPC+F1sO1IYKO5 MsGnmUMb0XixsM3D6LKDYb9b8RrOGhvsUcns8mwko2MY2tGPj4/M9bIYtR6EKFT+MqKV AgqQ==
X-Received by 10.152.234.227 with SMTP id uh3mr37301456lac.69.1415721630137; Tue, 11 Nov 2014 08:00:30 -0800 (PST)
MIME-Version 1.0
In-Reply-To <CACwCsY46yYFQwdYdriTSYSvLYF=xs6L2zanN9gofkWkoHvj_fA@mail.gmail.com>
References <CACwCsY46yYFQwdYdriTSYSvLYF=xs6L2zanN9gofkWkoHvj_fA@mail.gmail.com>
From Marc Aymerich <glicerinu@gmail.com>
Date Tue, 11 Nov 2014 17:00:09 +0100
Subject Re: Communicating with a PHP script (and pretending I'm a browser)
To Larry Martell <larry.martell@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15669.1415721637.18130.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415721637 news.xs4all.nl 2919 [2001:888:2000:d::a6]:35607
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80531

Show key headers only | View raw


On Tue, Nov 11, 2014 at 4:48 PM, Larry Martell <larry.martell@gmail.com> wrote:
>
> I have a PHP app that I want to convert to django. But I want to do it
> stages. All the heavy lifting is in the PHP code, so first, I want to
> just use templates and views to generate the HTML, but still call the
> PHP code. Then later convert the PHP to python.
>
> My issue is that the PHP code expects to get all it's input from the
> REQUEST object and I've consumed that in the view. Is there any way I
> can somehow supply that to the PHP code?
>
> Is there some way python can communicate like curl ... it needs to
> send the request string in the body of a POST request to the URL that
> will route to the PHP script and get the output back.


Yes,
I supose you can extract the needed information from the django
Request object and call the php script passing the needed variables as
environment state.

as a guideline you can do something like

cmd = (
    'REDIRECT_STATUS=200 '
    'REQUEST_METHOD=GET '
    'SCRIPT_FILENAME=htdocs/index.php '
    'SCRIPT_NAME=/index.php '
    'PATH_INFO=/ '
    'SERVER_NAME=site.tld '
    'SERVER_PROTOCOL=HTTP/1.1 '
    'REQUEST_URI=/nl/page '
    'HTTP_HOST=site.tld '
    '/usr/bin/php-cgi'
)
subprocess.Popen(cmd, stdout=subprocess.PIPE)



-- 
Marc

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Communicating with a PHP script (and pretending I'm a browser) Marc Aymerich <glicerinu@gmail.com> - 2014-11-11 17:00 +0100

csiph-web