الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

طلب مساعدة : طريقة تشغيل سكربت python

بدأه Mahammed Al-araby في 26 مايو 2010 · 5 رد · 2,196 مشاهدة · في لغة Python
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

سلام عليكم

كيف حالكم ياخواني الطيبين ؟ اتمنى ان تكونو في اتم الصحة و العافية

اريد طلب بسيط

انا ابغى اشغل الكود هذا

http://code.activestate.com/recipes/...tp-upload-cgi/

مع العلم انا حفظتة زي مو مكتوب بس ما اشتغل و انا شغال على ابونتو 9 و منذل اباتش و php و mysql و ادوات برمجية كثيرة

و عندي بعض الاستفسارات

الطلب هوا اني لمن احفظ ملف بيثون على السيرفر هل هوا نفس مكان php الي اشغل فية وﻻ ﻻ

و هل البرمشن ﻻزم 777 وﻻ ﻻ

و اخر شي ليش امتدادة cgi مو py مع اني شفت كود python

#3

http://code.activestate.com/recipes/273844-minimal-http-upload-cgi/

or

#!/usr/local/bin/python
"""This demonstrates a minimal http upload cgi.
This allows a user to upload up to three files at once.
It is trivial to change the number of files uploaded.

This script has security risks. A user could attempt to fill
a disk partition with endless uploads. 
If you have a system open to the public you would obviously want
to limit the size and number of files written to the disk.
"""
import cgi
import cgitb; cgitb.enable()
import os, sys
try: # Windows needs stdio set for binary mode.
    import msvcrt
    msvcrt.setmode (0, os.O_BINARY) # stdin  = 0
    msvcrt.setmode (1, os.O_BINARY) # stdout = 1
except ImportError:
    pass

UPLOAD_DIR = "/tmp"

HTML_TEMPLATE = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>File Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head><body><h1>File Upload</h1>
<form action="%(SCRIPT_NAME)s" method="POST" enctype="multipart/form-data">
File name: <input name="file_1" type="file"><br>
File name: <input name="file_2" type="file"><br>
File name: <input name="file_3" type="file"><br>
<input name="submit" type="submit">
</form>
</body>
</html>"""

def print_html_form ():
    """This prints out the html form. Note that the action is set to
      the name of the script which makes this is a self-posting form.
      In other words, this cgi both displays a form and processes it.
    """
    print "content-type: text/html\n"
    print HTML_TEMPLATE % {'SCRIPT_NAME':os.environ['SCRIPT_NAME']}

def save_uploaded_file (form_field, upload_dir):
    """This saves a file uploaded by an HTML form.
       The form_field is the name of the file input field from the form.
       For example, the following form_field would be "file_1":
           <input name="file_1" type="file">
       The upload_dir is the directory where the file will be written.
       If no file was uploaded or if the field does not exist then
       this does nothing.
    """
    form = cgi.FieldStorage()
    if not form.has_key(form_field): return
    fileitem = form[form_field]
    if not fileitem.file: return
    fout = file (os.path.join(upload_dir, fileitem.filename), 'wb')
    while 1:
        chunk = fileitem.file.read(100000)
        if not chunk: break
        fout.write (chunk)
    fout.close()

save_uploaded_file ("file_1", UPLOAD_DIR)
save_uploaded_file ("file_2", UPLOAD_DIR)
save_uploaded_file ("file_3", UPLOAD_DIR)

print_html_form ()
#4

لم افهم ماذا تريد جيدا و لكن جرب هذا

في Terminal اكتب

python filaname.py

حيث filename.py هو مسار الملف إذا كان في سطح المكتب سيكون المسار هكذا

/home/Username/Desktop/myfile.py

بسم الله الذي لا يضر مع اسمه شيء في الأرض و لا في السماء و هو السميع العليم

117tpo4.png
#5

هذي النتيجة

content-type: text/html

<!--: spam
Content-Type: text/html

<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> -->
<body bgcolor="#f0f0f8"><font color="#f0f0f8" size="-5"> --> -->
</font> </font> </font> </script> </object> </blockquote> </pre>
/usr/lib/python2.6/cgitb.py:173: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
  value = pydoc.html.repr(getattr(evalue, name))
</table> </table> </table> </table> </table> </font> </font> </font><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#6622aa">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><type 'exceptions.KeyError'></strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial">Python 2.6.4: /usr/bin/python<br>Thu May 27 14:48:25 2010</font></td></tr></table>

<p>A problem occurred in a Python script.  Here is the sequence of
function calls leading up to the error, in the order they occurred.</p>
<table width="100%" cellspacing=0 cellpadding=0 border=0>
<tr><td bgcolor="#d8bbff"><big> </big><a href="file:///home/pc-moon/Desktop/Learn/test.py">/home/pc-moon/Desktop/Learn/test.py</a> in <strong><module></strong>()</td></tr>
<tr><td><font color="#909090"><tt><small>   64</small> save_uploaded_file ("file_1", UPLOAD_DIR)<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt><small>   65</small> save_uploaded_file ("file_2", UPLOAD_DIR)<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt><small>   66</small> save_uploaded_file ("file_3", UPLOAD_DIR)<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt><small>   67</small> <br>
</tt></font></td></tr>
<tr><td bgcolor="#ffccee"><tt><small>   68</small> print_html_form ()<br>
</tt></td></tr>
<tr><td><small><font color="#909090"><strong>print_html_form</strong> = <function print_html_form at 0x9397d4c></font></small></td></tr></table>
<table width="100%" cellspacing=0 cellpadding=0 border=0>
<tr><td bgcolor="#d8bbff"><big> </big><a href="file:///home/pc-moon/Desktop/Learn/test.py">/home/pc-moon/Desktop/Learn/test.py</a> in <strong>print_html_form</strong>()</td></tr>
<tr><td><font color="#909090"><tt><small>   40</small>     """<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt><small>   41</small>     print "content-type: text/html\n"<br>
</tt></font></td></tr>
<tr><td bgcolor="#ffccee"><tt><small>   42</small>     print HTML_TEMPLATE % {'SCRIPT_NAME':os.environ['SCRIPT_NAME']}<br>
</tt></td></tr>
<tr><td><font color="#909090"><tt><small>   43</small> <br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt><small>   44</small> def save_uploaded_file (form_field, upload_dir):<br>
</tt></font></td></tr>
<tr><td><small><font color="#909090"><em>global</em> <strong>HTML_TEMPLATE</strong> = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Tra...e="submit" type="submit"><font color="#c040c0">\n</font></form><font color="#c040c0">\n</font></body><font color="#c040c0">\n</font></html>', <em>global</em> <strong>os</strong> = <module 'os' from '/usr/lib/python2.6/os.pyc'>, os.<strong>environ</strong> = {'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated...axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'}</font></small></td></tr></table>
<table width="100%" cellspacing=0 cellpadding=0 border=0>
<tr><td bgcolor="#d8bbff"><big> </big><a href="file:///usr/lib/python2.6/UserDict.py">/usr/lib/python2.6/UserDict.py</a> in <strong>__getitem__</strong>(self={'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated...axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'}, key='SCRIPT_NAME')</td></tr>
<tr><td><font color="#909090"><tt><small>   20</small>         if hasattr(self.__class__, "__missing__"):<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt><small>   21</small>             return self.__class__.__missing__(self, key)<br>
</tt></font></td></tr>
<tr><td bgcolor="#ffccee"><tt><small>   22</small>         raise KeyError(key)<br>
</tt></td></tr>
<tr><td><font color="#909090"><tt><small>   23</small>     def __setitem__(self, key, item): self.data[key] = item<br>
</tt></font></td></tr>
<tr><td><font color="#909090"><tt><small>   24</small>     def __delitem__(self, key): del self.data[key]<br>
</tt></font></td></tr>
<tr><td><small><font color="#909090"><em>builtin</em> <strong>KeyError</strong> = <type 'exceptions.KeyError'>, <strong>key</strong> = 'SCRIPT_NAME'</font></small></td></tr></table><p><strong><type 'exceptions.KeyError'></strong>: 'SCRIPT_NAME'
<br><tt><small>     </small> </tt>args =
('SCRIPT_NAME',)
<br><tt><small>     </small> </tt>message =
'SCRIPT_NAME'


<!-- The above is a description of an error in a Python program, formatted
     for a Web browser because the 'cgitb' module was enabled.  In case you
     are not reading this in a Web browser, here is the original traceback:

Traceback (most recent call last):
  File "test.py", line 68, in <module>
    print_html_form ()
  File "test.py", line 42, in print_html_form
    print HTML_TEMPLATE % {'SCRIPT_NAME':os.environ['SCRIPT_NAME']}
  File "/usr/lib/python2.6/UserDict.py", line 22, in __getitem__
    raise KeyError(key)
KeyError: 'SCRIPT_NAME'

-->
#6

نفس النتيجة عندما جربتها انا على جهازي بالرغم من اني لم اثبت لا php و لا apache و .....

أعتقد بأن استعمال python للويب يحتاج لسيرفر خاص به او frameworks خاصة به

انظر لهذا الرابط

و حاول تجربة أحد ال frameworks المذكورة هناك....

شكرا :)

بسم الله الذي لا يضر مع اسمه شيء في الأرض و لا في السماء و هو السميع العليم

117tpo4.png

مواضيع مشابهة