Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Python script, WMI and Dyn. webserver

If you have a question or need help, this is the place to be.
Post Reply
hanspettersson
Posts: 42
Joined: Sat Feb 20, 2010 2:42 pm

Python script, WMI and Dyn. webserver

Post by hanspettersson »

I have this python script:

Code: Select all

import wmi
c = wmi.WMI ()

for disk in c.Win32_LogicalDisk (DriveType=3):
    disk.Caption, "%0.2f%% free" % (100.0 * long (disk.FreeSpace) / long (disk.Size))

print long (disk.FreeSpace) / long (1073741824 )
print long (disk.Size) / long (1073741824 )

eg.globals.enhet_c_ledigt = long (disk.FreeSpace) / long (1073741824 )
And then i show the result of eg.globals.enhet_c_ledigt in my webpage whit :
{{eg.globals.enhet_c_ledigt}}

And then i get an error in EG

Code: Select all

Webserver socket error /
<type 'exceptions.Exception'> sequence item 1: expected string, long found
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 1962)
Traceback (most recent call last):
  File "SocketServer.pyc", line 281, in _handle_request_noblock
  File "SocketServer.pyc", line 307, in process_request
  File "SocketServer.pyc", line 320, in finish_request
  File "SocketServer.pyc", line 615, in __init__
  File "BaseHTTPServer.pyc", line 329, in handle
  File "BaseHTTPServer.pyc", line 323, in handle_one_request
  File "C:\Program\EventGhost\plugins\Webserver\__init__.py", line 114, in do_GET
  File "re.pyc", line 151, in sub
TypeError: sequence item 1: expected string, long found
----------------------------------------
stottle
Plugin Developer
Posts: 636
Joined: Sun Apr 26, 2009 10:59 pm

Re: Python script, WMI and Dyn. webserver

Post by stottle »

You could try

Code: Select all

eg.globals.enhet_c_ledigt = "%d"%long (disk.FreeSpace) / long (1073741824 )
which just prints the long as a string.

Brett
hanspettersson
Posts: 42
Joined: Sat Feb 20, 2010 2:42 pm

Re: Python script, WMI and Dyn. webserver

Post by hanspettersson »

I get this error :

Code: Select all

   Traceback (most recent call last):
     Python script "63", line 10, in <module>
       eg.globals.enhet_c_ledigt = "%d"%long (disk.FreeSpace) / long (1073741824 )
   TypeError: unsupported operand type(s) for /: 'str' and 'long'
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Python script, WMI and Dyn. webserver

Post by krambriw »

Why not just

Code: Select all

eg.globals.enhet_c_ledigt = str(long (disk.FreeSpace) / long (1073741824 ))
hanspettersson
Posts: 42
Joined: Sat Feb 20, 2010 2:42 pm

Re: Python script, WMI and Dyn. webserver

Post by hanspettersson »

krambriw wrote:Why not just

Code: Select all

eg.globals.enhet_c_ledigt = str(long (disk.FreeSpace) / long (1073741824 ))
Thank you!
Works great
Post Reply