인문지식 처리와 프로그래밍2020 5.21

soook
이동: 둘러보기, 검색

python 파일 코딩

Hello.py

#!/usr/bin/env python

import cgi

html = """
<html>
<head>
<title>Hello Word - First CGI Program</title>
</head>
<body>
<h2>Hello Word! This is my first py CGI program</h2>
</body>
</html>"""

print "Content-type:text/html\n\n"
print html


Hello1.py

#!/usr/bin/env python

import cgi #cgi 를 쓰기위해

html = """  #여러행의 변수를 하나의 변수로 넣기위해"""를쓴다 한글은 문제 버전2
<html>
<head>
<title>Hello Word - First CGI Program</title>
</head>
<body>
<h2>Hello Word! This is my first py CGI program</h2>
</body>
</html>"""

print "Content-type:text/html\n\n" #내가 이후 텍스트는 CGI통해 쓴다는 것 알리는 그다음 프린트문은 웹뭄서한줄한줄... 송두리째 
print html




Hello2.py

#!/usr/bin/python
#-*- coding: utf-8 -*-

import cgi
import cgitb

html = """
<html>
<head>
<title>Hello Word - First CGI Program</title>
</head>
<body>
<h2>Hello Word! This is my first py CGI program</h2>
</body>
</html>"""

print "Content-type:text/html\n\n"
print html


Hello3.py

#!/usr/bin/python
#-*- coding: utf-8 -*-

import sys
import cgi
import cgitb



print "Content-type:text/html\n\n"
print "<h2>Hello World 안녕</h2>"

  • 파일 우측하단설정에서 인코딩utf-8/ Unix(Lf)로 바꾸고 저장

Python파일을 FTP연결하고>dh.aks.ac.kr>cgi-bin 에 저장

(cgi-bin은 파이선파일이 인터넷상에 올릴수 있는 음식이되게하는 전자렌지다)
cf) odbc는 SQL서버(digerati.aks.ac.kr)에 올린 data를 sql문으로 불러와 파이썬 코딩을 실행해서 보여주는 것이다

putty 연결

HostName : dh.aks.ac.kr
port : 7778
type : SSH
saved Session : soook
only on clean exit
open

putty

cgi-bin에 저장한것을 불러와 인터넷에 보여주게하는것
putty는 리눅스다.

login as: soook
soook@dh.aks.ac.kr's password:
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-72-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

722 packages can be updated.
0 updates are security updates.

New release '18.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


Last login: Fri Mar 13 10:57:30 2020 from 125.132.153.101
soook@dh:~$ ls
public_html
soook@dh:~$ cd public_html
soook@dh:~/public_html$ ls
cgi-bin  graph  mediawiki-1.27.4.tar.gz  pavilion  SoookArt  wiki
soook@dh:~/public_html$ ls
cgi-bin  graph  mediawiki-1.27.4.tar.gz  pavilion  SoookArt  wiki
soook@dh:~/public_html$ dir
cgi-bin  graph  mediawiki-1.27.4.tar.gz  pavilion  SoookArt  wiki
soook@dh:~/public_html$ cd ..
soook@dh:~$ ls
public_html
soook@dh:~$ cd public_html
soook@dh:~/public_html$ ls
cgi-bin  graph  mediawiki-1.27.4.tar.gz  pavilion  SoookArt  wiki
soook@dh:~/public_html$ cd cgi-bin
soook@dh:~/public_html/cgi-bin$ ls
soook@dh:~/public_html/cgi-bin$ ls Hello.py
Hello.py
soook@dh:~/public_html/cgi-bin$ chmode + rwx Hello.py
No command 'chmode' found, did you mean:
 Command 'chmod' from package 'coreutils' (main)
chmode: command not found
soook@dh:~/public_html/cgi-bin$ ch m
ch: command not found
soook@dh:~/public_html/cgi-bin$ ch mode +rwx Hello.py
ch: command not found
soook@dh:~/public_html/cgi-bin$ cdmod +rwx Hello.py
No command 'cdmod' found, did you mean:
 Command 'chmod' from package 'coreutils' (main)
cdmod: command not found
soook@dh:~/public_html/cgi-bin$ chmod +rwx hello.py
chmod: cannot access 'hello.py': No such file or directory
soook@dh:~/public_html/cgi-bin$ ls
Hello.py
soook@dh:~/public_html/cgi-bin$ chmod +rwx Hello.py
soook@dh:~/public_html/cgi-bin$ ls
Hello.py
soook@dh:~/public_html/cgi-bin$ python Hello.py
Content-type:text/html



<html>
<head>
<title>Hello Word - First CGI Program</title>
</head>
<body>
<h2>Hello Word! This is my first py CGI program</h2>
</body>
</html>

soook@dh:~/public_html/cgi-bin$ ls
Hello.py(성공했으면 초록색으로 색이 바뀜)
soook@dh:~/public_html/cgi-bin$ chmod +rwx Hello.py
soook@dh:~/public_html/cgi-bin$ ls
Hello.py
soook@dh:~/public_html/cgi-bin$ python Hello.py

  • ls =dir
  • chmod : change mode
  • +r read
  • w write

+rwx read / write / execute 읽기 쓰기 실행 권한을 추가하라는 명령어입니다 선애샘정리



http://dh.aks.ac.kr/~soook/cgi-bin/Hello.py


Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
login as: soook
soook@dh.aks.ac.kr's password:
Welcome to Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-72-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

722 packages can be updated.
0 updates are security updates.

New release '18.04.4 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


Last login: Thu May 21 18:00:29 2020 from 125.132.153.101
soook@dh:~$ vi Hello3.py
soook@dh:~$

vi 리눅스 에디터

: w q !

w

노트패드변경하면---저장하고 FTP/ cgi bin 에올린다 chmod +rwx Hello2.py