Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Inserting-embedding some html data at the end of a .py file

Reply
Thread Tools

Re: Inserting-embedding some html data at the end of a .py file

 
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-05-2013
Thank you very much! This is what i was looking for and here is my code after receiving your help.
So, with the command you provided to me i can actually run the .py script ans save its output and then append from there!! Great!

Here is my code now!
====================================
if htmlpage.endswith('.html'):
f = open( "/home/nikos/public_html/" + htmlpage )
htmldata = f.read()
elif htmlpage.endswith('.py'):
htmldata = subprocess.check_output( open( "/home/nikos/public_html/cgi-bin/" + htmlpage ) )


counter = ''' <center><a href="(E-Mail Removed)"> <img src="/data/images/mail.png"> </a>
<center><table border=2 cellpadding=2 bgcolor=black>
<td><font color=lime>Αριθμός Επισκεπτών</td>
<td><a href="http://superhost.gr/?show=stats"><font color=cyan> %d </td>
''' % data[0]


template = htmldata + counter
print ( template )
=======================================

But i'am getting this error:
<type 'exceptions.AttributeError'>: 'module' object has no attribute 'check_output'

Why does it say it has no attribute?
 
Reply With Quote
 
 
 
 
Michael Ross
Guest
Posts: n/a
 
      03-05-2013
On Tue, 05 Mar 2013 23:47:18 +0100, Νίκος Γκρ33ΞΊ <(E-Mail Removed)>
wrote:

> Thank you very much! This is what i was looking for and here is my code
> after receiving your help.
> So, with the command you provided to me i can actually run the .py
> script ans save its output and then append from there!! Great!
>
> Here is my code now!
> ====================================
> if htmlpage.endswith('.html'):
> f = open( "/home/nikos/public_html/" + htmlpage )
> htmldata = f.read()
> elif htmlpage.endswith('.py'):
> htmldata = subprocess.check_output( open(
> "/home/nikos/public_html/cgi-bin/" + htmlpage ) )
>
>
> counter = ''' <center><a href="(E-Mail Removed)"> <img
> src="/data/images/mail.png"> </a>
> <center><table border=2 cellpadding=2 bgcolor=black>
> <td><font color=lime>Ξ‘ΟΞΉΞΈΞΌΟŒΟ‚ Ξ•Ο€ΞΉΟƒΞΊΞ΅Ο€Ο„ΟŽΞ½</td>
> <td><a href="http://superhost.gr/?show=stats"><font color=cyan> %d
> </td>
> ''' % data[0]
>
>
> template = htmldata + counter
> print ( template )
> =======================================
>
> But i'am getting this error:
> <type 'exceptions.AttributeError'>: 'module' object has no attribute
> 'check_output'
>
> Why does it say it has no attribute?


Python version < 2.7 ?

And it's more along the lines of
subprocess.check_output( '/home/nikos/.../' + htmlpage )
without "open".
Or even
subprocess.check_output( [ '/your/python/interpreter', '/home/nikos/...'
] )
 
Reply With Quote
 
 
 
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-05-2013
htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + htmlpage )

htmldata = subprocess.check_output( ['/usr/bin/python', '/home/nikos/public_html/cgi-bin/' + htmlpage] )

Both of the above statemnts fail i'am afraid with the same error message.
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-05-2013
htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' + htmlpage )

htmldata = subprocess.check_output( ['/usr/bin/python', '/home/nikos/public_html/cgi-bin/' + htmlpage] )

Both of the above statemnts fail i'am afraid with the same error message.
 
Reply With Quote
 
Michael Ross
Guest
Posts: n/a
 
      03-06-2013
On Wed, 06 Mar 2013 00:39:31 +0100, Νίκος Γκρ33ΞΊ <(E-Mail Removed)>
wrote:

> htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' +
> htmlpage )
>
> htmldata = subprocess.check_output( ['/usr/bin/python',
> '/home/nikos/public_html/cgi-bin/' + htmlpage] )
>
> Both of the above statemnts fail i'am afraid with the same error message.



check_output is available as of Python 2.7

I guess you are still on version 2.6 ?


 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-06-2013
Τη Τετάρτη, 6 Μαρτίου 2013 2:06:33 π.μ.UTC+2, ο χρήστης Michael Ross έγραψε:
> On Wed, 06 Mar 2013 00:39:31 +0100, Νίκος Γκρ33κ
>
> wrote:
>
>
>
> > htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' +

>
> > htmlpage )

>
> >

>
> > htmldata = subprocess.check_output( ['/usr/bin/python',

>
> > '/home/nikos/public_html/cgi-bin/' + htmlpage] )

>
> >

>
> > Both of the above statemnts fail i'am afraid with the same error message.


> check_output is available as of Python 2.7
> I guess you are still on version 2.6 ?


Actually i'am runnign myu cgi script on my hostgator remote web hosting.
How dod i check the version of python the server uses?
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-06-2013
Τη Τετάρτη, 6 Μαρτίου 2013 2:06:33 π.μ.UTC+2, ο χρήστης Michael Ross έγραψε:
> On Wed, 06 Mar 2013 00:39:31 +0100, Νίκος Γκρ33κ
>
> wrote:
>
>
>
> > htmldata = subprocess.check_output( '/home/nikos/public_html/cgi-bin/' +

>
> > htmlpage )

>
> >

>
> > htmldata = subprocess.check_output( ['/usr/bin/python',

>
> > '/home/nikos/public_html/cgi-bin/' + htmlpage] )

>
> >

>
> > Both of the above statemnts fail i'am afraid with the same error message.


> check_output is available as of Python 2.7
> I guess you are still on version 2.6 ?


Actually i'am runnign myu cgi script on my hostgator remote web hosting.
How dod i check the version of python the server uses?
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-06-2013
Τη Τετάρτη, 6 Μαρτίου 2013 2:06:33 π.μ.UTC+2, ο χρήστης Michael Ross έγραψε:

> check_output is available as of Python 2.7
>
>
>
> I guess you are still on version 2.6 ?


Indeed!
i just checked it's Python 2.6.6: /usr/bin/python and i have asked the linxu admins @ hostgator.com to update python.

I trust when they update to v2.7 the script will automatically work!
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-06-2013
Τη Τετάρτη, 6 Μαρτίου 2013 2:06:33 π.μ.UTC+2, ο χρήστης Michael Ross έγραψε:

> check_output is available as of Python 2.7
>
>
>
> I guess you are still on version 2.6 ?


Indeed!
i just checked it's Python 2.6.6: /usr/bin/python and i have asked the linxu admins @ hostgator.com to update python.

I trust when they update to v2.7 the script will automatically work!
 
Reply With Quote
 
Νίκος Γκρ33κ
Guest
Posts: n/a
 
      03-06-2013
Τη Τετάρτη, 6 Μαρτίου 2013 2:06:33 π.μ.UTC+2, ο χρήστης Michael Ross έγραψε:

> check_output is available as of Python 2.7
> I guess you are still on version 2.6 ?



I can access each of these from my jailed shell user account without issue,and especially i try /usr/bin/python3

http://www.velocityreviews.com/forums/(E-Mail Removed) [~]# /usr/bin/python -V
Python 2.6.6

(E-Mail Removed) [~]# /opt/python3/bin/python3 -V
Python 3.2.3

(E-Mail Removed) [~]# /usr/bin/python3 -V
Python 3.2.3


Problem is that when i change my shebang constructor to #!/sur/bin/python3 my '/cgi-bin/metrites.py' python cgi scripts produces an internal server error while with #!/sur/bin/python the script works.

Any ideas as to why? I can post ocde if you want to.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ Python 9 03-06-2013 09:00 AM
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ Python 4 03-05-2013 10:49 PM
Re: Inserting-embedding some html data at the end of a .py file Νίκος Γκρ33κ Python 2 03-05-2013 05:25 PM
Is a blank at the end of a C file a better style than a newline atthe end of the file or is it better to place none? Jimmy C Programming 13 09-21-2011 12:17 AM
Is a blank at the end of a C file a better style than a newline atthe end of the file or is it better to place none? Jimmy C Programming 3 09-09-2011 10:36 PM



Advertisments