{"id":10627,"date":"2021-10-28T03:47:31","date_gmt":"2021-10-28T03:47:31","guid":{"rendered":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=10627"},"modified":"2022-01-03T03:58:24","modified_gmt":"2022-01-03T03:58:24","slug":"mod_wsgi-%e3%82%92%e5%88%a9%e7%94%a8%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=10627","title":{"rendered":"mod_wsgi \u3092\u5229\u7528\u3059\u308b"},"content":{"rendered":"<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028c.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028c-300x184.png\" alt=\"\" width=\"300\" height=\"184\" class=\"aligncenter size-medium wp-image-10628\" srcset=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028c-300x184.png 300w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028c-1024x629.png 1024w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028c-768x472.png 768w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028c-600x369.png 600w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028c.png 1107w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>python \u3092 apache \u3067\u5b9f\u884c\u3059\u308b\u3053\u3068\u3092\u8a66\u3057\u3066\u3044\u307e\u3059\u3002php \u304b\u3089 python \u3092 exec \u7b49\u3067\u547c\u3073\u51fa\u3057\u305f\u3068\u304d\u306b\uff0c\u3069\u3046\u3082\u6642\u9593\u304c\u304b\u304b\u308a\u3059\u304e\u307e\u3059\u3002\u305d\u308c\u3067\uff0c\u4ed6\u306e\u3084\u308a\u65b9\u3068\u3057\u3066\uff0capache \u306e mod_wsgi \u3092\u8a66\u3057\u3066\u307f\u307e\u3059\u3002OS \u306f ubuntu 20.04 \u3067\u3059\u3002synaptic \u304b\u3089 libapache2-mod-wsgi-py3 \u3092\u5c0e\u5165\u3057\u307e\u3059\uff08\u4f3c\u305f\u3082\u306e\u304c\u4e8c\u3064\u3042\u308a\u307e\u3059\u304c\uff0cpy3 \u304c\u4ed8\u3044\u3066\u3044\u308b\u65b9\u304c\u826f\u3044\u3068\u4f55\u51e6\u304b\u306b\u66f8\u3044\u3066\u3042\u3063\u305f\uff09\u3002<\/p>\n<p>\u30cd\u30c3\u30c8\u306b\u3042\u308b\u8a18\u4e8b\u304c\u3042\u3066\u306f\u307e\u3089\u306a\u304f\u3066\u8a66\u884c\u932f\u8aa4\u3057\u307e\u3057\u305f\u3002conf-available\/mod-wsgi.conf \u306b <\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">WSGIScriptAlias \/test_wsgi \/var\/www\/scripts\/test_wsgi_script.py<\/code><\/pre>\n<p>\u4e0a\u8a18\u3088\u3046\u306a\u30b3\u30fc\u30c9\u3092\u8a18\u5165\u3057\u308d\u3068\u3044\u3046\u8a18\u4e8b\u304c\u591a\u304f\u3042\u308b\u306e\u3067\u3059\u304c\uff0c\u3053\u306e\u540d\u524d\u306e\u30d5\u30a1\u30a4\u30eb\u306f\u3042\u308a\u307e\u305b\u3093\u3002<a href=\"https:\/\/ubuntu.pkgs.org\/20.04\/ubuntu-main-arm64\/libapache2-mod-wsgi-py3_4.6.8-1ubuntu3_arm64.deb.html\">\u3053\u306e\u30da\u30fc\u30b8<\/a>\u306b\u3088\u308b\u3068\uff0cwsgi.conf \u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u76f8\u5f53\u3059\u308b\u3088\u3046\u3067\u3059\u3002\u3069\u3053\u306b\u4f55\u3092\u66f8\u3044\u3066\u3088\u3044\u306e\u304b\u5206\u304b\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u3059\u304c\uff0c\u4e0b\u56f3\u306e\u3088\u3046\u306b\u8a18\u5165\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028b.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028b-300x249.png\" alt=\"\" width=\"300\" height=\"249\" class=\"aligncenter size-medium wp-image-10633\" srcset=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028b-300x249.png 300w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028b-768x637.png 768w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028b-600x498.png 600w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028b.png 906w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\/var\/www\/script\/ \u3068\u3044\u3046\u30d5\u30a9\u30eb\u30c0\u30fc\u3092\u7528\u610f\u3057\u3066\uff0c\u305d\u3053\u306b hello.py \u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u7f6e\u304d\u307e\u3057\u305f\u3002\u305d\u306e\u4e2d\u8eab\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028a.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028a-300x249.png\" alt=\"\" width=\"300\" height=\"249\" class=\"aligncenter size-medium wp-image-10636\" srcset=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028a-300x249.png 300w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028a-768x638.png 768w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028a-600x499.png 600w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028a.png 905w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u30b3\u30fc\u30c9\u306f<a href=\"https:\/\/qiita.com\/shigechiyo\/items\/2b25f60918be6b81581a\">\u3053\u3061\u3089\u304b\u3089<\/a>\u3002\u30d5\u30a1\u30a4\u30eb\u306b\u5b9f\u884c\u6a29\u9650\u3092\u4e0e\u3048\u307e\u3057\u305f\u3002apache \u3092\u518d\u8d77\u52d5\u3057\u305f\u5f8c\uff0capache \u306e URL \u306f 192.168.100.4 \u306a\u306e\u3067\u3059\u304c\uff0c<code>http:\/\/192.168.100.4\/hello<\/code> \u306b\u30a2\u30af\u30bb\u30b9\u3092\u3057\u3066\u307f\u308b\u3068\u4e0b\u8a18\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<p><a href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028d.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028d-300x159.png\" alt=\"\" width=\"300\" height=\"159\" class=\"aligncenter size-medium wp-image-10639\" srcset=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028d-300x159.png 300w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028d-600x318.png 600w, http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/wp-content\/uploads\/2021\/10\/20211028d.png 673w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u5206\u304b\u3089\u306a\u3044\u3053\u3068\u304c\u591a\u3044\u306e\u3067\u3059\u304c\uff0c\u52d5\u3044\u305f\uff01<\/p>\n<p><strong>(20211105)<\/strong><br \/>\nwsgi \u306e\u5229\u7528\u306f\u76f4\u63a5\u547c\u3073\u51fa\u3059\u306e\u3067\u306f\u306a\u304f\u3066\uff0cPHP \u306e\u51e6\u7406\u306e\u9014\u4e2d\u3067 PHP \u304b\u3089\u547c\u3073\u51fa\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u306f file_get_contents \u3092\u4f7f\u7528\u3057\u307e\u3059\uff08<a href=\"https:\/\/blog.codebase.co.jp\/http-request-with-php\">\u53c2\u8003\u30b5\u30a4\u30c8<\/a>\uff09\u3002python \u304c\u5b9f\u884c\u3059\u308b\u30b3\u30fc\u30c9\u3092\u6587\u5b57\u5217\u3067\u6e21\u3057\u3066\u8272\u3005\u51e6\u7406\u3092\u5b9f\u884c\u3057\u305f\u3044\u3002\u6587\u5b57\u5217\u306f GET \u3067\u6e21\u3057\u307e\u3059\u3002python \u3092\u547c\u3073\u51fa\u3059 PHP \u306e\u30b3\u30fc\u30c9\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u30021\u884c\u3060\u3051\u306e python \u30b3\u30fc\u30c9\u3092\u6e21\u3057\u307e\u3059\u3002\u5909\u6570 a \u3092\u5b9a\u7fa9\u3059\u308b\u3060\u3051\u306e\u5185\u5bb9\u3067\u3059\u3002<\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">&lt;?php\r\n$starttime = microtime(true);\r\n$tmp = &lt;&lt;&lt; end_of_quote\r\na = 'python!'\r\nend_of_quote;\r\n$tmpBase64 = base64_encode($tmp);\r\n\r\n$context = stream_context_create([\r\n    'http' =&gt; [\r\n\t'ignore_errors' =&gt; true\r\n    ]\r\n]);\r\n\r\n$res = file_get_contents(&quot;http:\/\/192.168.100.9\/hello?$tmpBase64&quot;, false, $context);\r\necho $res . &quot;&lt;br&gt;&quot;;\r\n$now = microtime(true);\r\necho &quot;Start: {$starttime}, End: {$now}, Taken = &quot; .($now - $starttime).&quot;\\n&quot;;\r\n?&gt;<\/code><\/pre>\n<p>\u6642\u9593\u8a08\u6e2c\u306e\u30b3\u30fc\u30c9\u3082\u3064\u3044\u3066\u3044\u307e\u3059\u3002GET \u3067\u6587\u5b57\u5217\u3092\u6e21\u3059\u306e\u3067\uff0c\u305d\u306e\u307e\u307e\u3060\u3068\u6587\u5b57\u5217\u4e2d\u306e\u30b9\u30da\u30fc\u30b9\u306a\u3069\u304c\u5909\u63db\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3059\u3002\u305d\u306e\u70ba\uff0c\u6587\u5b57\u5217\u3092 Base64 \u5909\u63db\u3057\u3066\uff0cpython \u5074\u3067\u3082\u3068\u306b\u623b\u3059\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002\u6b21\u306b python \u5074\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002\u5909\u6570 a \u306e\u5024\u3092\u8fd4\u3059\u3060\u3051\u306e\u30b3\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">def application(environ, start_response):    \r\n    import sys, os\r\n    import base64    \r\n    global a \r\n    \r\n    tmpStr = environ.get('QUERY_STRING')\r\n    tmpStrBina = tmpStr.encode()    \r\n    tmpDecodeStr = base64.b64decode(tmpStrBina).decode()\r\n        \r\n    exec(tmpDecodeStr, globals())\r\n    output = a.encode()\r\n\r\n    status = '200 OK'\r\n    response_headers = [('Content-type', 'text\/plain'),\r\n                        ('Content-Length', str(len(output)))]\r\n    start_response(status, response_headers)\r\n    return [output]<\/code><\/pre>\n<p>environ.get(&#8216;QUERY_STRING&#8217;) \u3067 GET \u3067\u306e\u9001\u4fe1\u5185\u5bb9\u3092\u53d7\u3051\u53d6\u308a\u307e\u3059\u3002\u5229\u7528\u3057\u3066\u3044\u308b Base64 \u5909\u63db\u306e\u95a2\u6570\u306f\uff0c\u30d0\u30a4\u30ca\u30ea\u30fc\u3092\u53d7\u3051\u4ed8\u3051\u307e\u3059\u3002\u51fa\u529b\u3082\u30d0\u30a4\u30ca\u30ea\u30fc\u3067\u3059\u3002\u305d\u308c\u3067\uff0c\u5165\u529b\u3068\u51fa\u529b\u306e\u969b\u306b\u5909\u63db\u51e6\u7406\u304c\u5165\u3063\u3066\u3044\u307e\u3059\u3002PHP \u306b\u5024\u3092\u8fd4\u3059\u3068\u3053\u308d\u3082 \u30a8\u30f3\u30b3\u30fc\u30c9\u51e6\u7406\u3092\u3044\u308c\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u3088\u3046\u3067\u3059\u3002<br \/>\n\u3000\u30dd\u30a4\u30f3\u30c8\u306f <code>global a<\/code> \u3068\u3044\u3046\u5ba3\u8a00\u3067\u3059\u3002GET \u3067\u53d7\u3051\u53d6\u3063\u305f python \u30b3\u30fc\u30c9\u3092 exec \u3067\u5b9f\u884c\u3057\u307e\u3059\u304c\uff0c\u305d\u308c\u306f\u30b0\u30ed\u30fc\u30d0\u30eb\u306e\u9818\u57df\u306e\u3088\u3046\u3067\uff0c\u5ba3\u8a00\u7121\u3057\u3067\u306f\uff0c\u95a2\u6570\u5185\u304b\u3089 a \u3092\u53c2\u7167\u3057\u3066\u3082\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">NameError: name 'a' is not defined<\/code><\/pre>\n<p>numpy \u3068\u304b pandas \u3068\u304b\u3082\u5229\u7528\u3057\u305f\u3044\u306e\u3067\u3059\u304c\uff0cGET \u3067\u6e21\u3059\u6587\u5b57\u5217\u306b import \u6587 \u3092\u542b\u3081\u3066\u3057\u307e\u3048\u3070\u5229\u7528\u3067\u304d\u307e\u3059\u3002\u30b0\u30ed\u30fc\u30d0\u30eb\u306a\u9818\u57df\u306b\u8aad\u307f\u8fbc\u3093\u3060\u3053\u3068\u306b\u306a\u308b\u306e\u304b\u306a\u3068\u601d\u3044\u307e\u3059\u3051\u3069\uff0c\u6bce\u56de python \u3092\u547c\u3073\u51fa\u3059\u969b\u306b import \u3059\u308b\u306e\u306f\uff0c\u6642\u9593\u304c\u304b\u304b\u308b\u306e\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3063\u3066\uff0c\u4e0b\u8a18\u306e\u3088\u3046\u306a\u5ba3\u8a00\u3092\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">    global pd, np, sympy\r\n    import pandas as pd\r\n    import numpy as np\r\n    import sympy\r\n<\/code><\/pre>\n<p>\u610f\u5916\u306b\u3053\u308c\u3067\uff0cGET \u3067\u6e21\u3059\u30b3\u30fc\u30c9\u5185\u3067 numpy \u7b49\u304c\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p><strong>(20211228) POST \u3067\u6e21\u3059<\/strong><\/p>\n<p>GET \u3067\u6e21\u305b\u308b\u30c7\u30fc\u30bf\u306b\u306f\u5927\u304d\u3055\u306e\u5236\u9650\u304c\u3042\u308b\u306e\u3067\u3001\u52d5\u753b\u3092 base64 \u306b\u5909\u63db\u3057\u305f\u30c7\u30fc\u30bf\u306a\u3069\u306f POST \u3067\u6e21\u3059\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\uff08<a href=\"https:\/\/qiita.com\/yagays\/items\/e59731b3930252b5f0c4\">\u53c2\u8003\u30b5\u30a4\u30c8<\/a>\uff09\u3002\u518d\u3073\u3001 PHP \u304b\u3089 wsgi \u3078\u30a2\u30af\u30bb\u30b9\u3059\u308b\u5834\u5408\u3092\u8003\u3048\u307e\u3059\u3002\u4ee5\u4e0b\u3067\u306f hello! \u3068\u3044\u3046\u6587\u5b57\u3092\u6e21\u3057\u307e\u3059\u3002<\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">&lt;?php\r\n$mess = 'hello!';\r\n$postdata = http_build_query(array('postData' =&gt; $mess));\r\n\r\n$headers = array(\r\n    'Content-Type: application\/x-www-form-urlencoded',\r\n    'Content-Length: '.strlen($postdata)\r\n    );\r\n\r\n$context = stream_context_create([\t\r\n\t'http' =&gt; ['method'  =&gt; 'POST',\r\n\t\t'header'=&gt;implode( &quot;\\r\\n&quot;, $headers),\r\n\t\t'ignore_errors' =&gt; true,\r\n\t\t'content' =&gt; $postdata\r\n\t]\t\r\n]);\r\n\r\n$res = file_get_contents(&quot;http:\/\/xxx.xxx.xxx.xxx\/wsgi&quot;, false, $context);\r\n\r\nif (strpos($http_response_header[0], '200') !== false) {\r\n\techo base64_decode($res) . &quot;\\n&quot;;\r\n} else {\r\n\techo &quot;file_get_contents false&quot; . &quot;\\n&quot;;\r\n}\r\n?&gt;<\/code><\/pre>\n<p>\u53d7\u3051\u308b\u65b9\u306f\u4e0b\u8a18\u3002\u53d7\u3051\u53d6\u3063\u305f\u6587\u5b57\u5217 hello! \u3092\u8fd4\u3059\u3060\u3051\u3067\u3059\u3002<\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">def application(environ, start_response):\r\n    \r\n    import sys, os\r\n    import base64\r\n    \r\n    import pandas as pd\r\n\r\n    import urllib\r\n    \r\n    content_length = environ.get('CONTENT_LENGTH', 0)    \r\n    body = environ.get('wsgi.input').read(int(content_length))    \r\n    bodyString = body.decode()\r\n    \r\n    tmpObj = urllib.parse.parse_qs(bodyString)\r\n    tmpStr = tmpObj['postData'][0]\r\n   \r\n    status = '200 OK'    \r\n    output = base64.b64encode(tmpStr.encode())\r\n    #output = base64.b64encode(bodyString.encode())\r\n\r\n    response_headers = [('Content-type', 'text\/plain'),\r\n                        ('Content-Length', str(len(output)))]\r\n    start_response(status, response_headers)    \r\n\r\n    return [output]<\/code><\/pre>\n<p>python \u306e\u6587\u5b57\u5217\u306b\u306f2\u7a2e\u985e\u3042\u308b\u3088\u3046\u3067\uff08<a href=\"https:\/\/go-journey.club\/archives\/6922\">\u53c2\u8003\u30b5\u30a4\u30c8<\/a>\uff09\u3001\u30b3\u30fc\u30c9\u4e2d\u306e body \u306f\u30d0\u30a4\u30c8\u578b\u306e\u3088\u3046\u3067\u3059\u3002\u30d0\u30a4\u30c8\u578b\u306f str \u578b\u306b\u5909\u63db\u3057\u306a\u3044\u3068\u3001\u30a8\u30f3\u30b3\u30fc\u30c9\u3059\u308b\u5834\u5408\u306a\u3069\u4e0b\u8a18\u306e\u3088\u3046\u306a\u30a8\u30e9\u30fc\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">'bytes' object has no attribute 'encode'<\/code><\/pre>\n<p>tmpObj \u306e\u5f62\u304c\u3088\u304f\u308f\u304b\u308a\u307e\u305b\u3093\u3002\u3068\u306b\u304b\u304f tmpObj[&#8216;postData&#8217;] \u306f\u4e2d\u8eab\u304c1\u500b\u306e\u914d\u5217\u3067\u3059\u3002urllib \u3092\u5229\u7528\u3059\u308b\u305f\u3081\u306b\u3001pandas \u304c\u5fc5\u8981\u3060\u3063\u305f\u3088\u3046\u306a\u6c17\u304c\u3057\u307e\u3059\u3002<\/p>\n<p><strong>(20220103) \u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5229\u7528\u3059\u308b<\/strong><\/p>\n<p>\u8a71\u304c wsgi \u304b\u3089\u96e2\u308c\u308b\u306e\u3067\u3059\u304c\u3001\u5206\u3051\u308b\u307b\u3069\u306e\u5185\u5bb9\u3082\u306a\u3044\u306e\u3067\u3001\u3053\u3053\u306b\u66f8\u304d\u307e\u3059\u3002\u6700\u7d42\u7684\u306b\u306f wsgi \u306e\u4e2d\u3067\u3001ffmpeg \u306a\u3069\u306e\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u5229\u7528\u3057\u305f\u3044\u306e\u3067\u3001\u5c11\u3057\u8abf\u3079\u3066\u898b\u307e\u3057\u305f\uff08<a href=\"https:\/\/maku77.github.io\/python\/env\/call-external-program.html\">\u53c2\u8003\u30b5\u30a4\u30c8<\/a>\uff09\u3002 \u3053\u3093\u306a\u611f\u3058\u3067\u5229\u7528\u3057\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002ffmpeg \u3067\u52d5\u753b\u306e\u60c5\u5831\u3092\u63a2\u308a\u307e\u3059\u3002<\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">import sys, os\r\nimport subprocess\r\n\r\ntry:\r\n    result = subprocess.run('ffprobe -v quiet -hide_banner -show_streams -print_format json \/var\/www\/html\/temporary\/tmp1641143261925888.mp4', shell=True, check=True,\r\n            stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)\r\n    feedback = result.stdout\r\n    print(feedback)\r\nexcept subprocess.CalledProcessError:\r\n    print('\u5916\u90e8\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u5b9f\u884c\u306b\u5931\u6557\u3057\u307e\u3057\u305f', file=sys.stderr)\r\n<\/code><\/pre>\n<p>\u51fa\u529b\u7d50\u679c\u306f\u4e0b\u8a18\u3002<\/p>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\">{\r\n    \"streams\": [\r\n        {\r\n            \"index\": 0,\r\n            \"codec_name\": \"h264\",\r\n            \"codec_long_name\": \"H.264 \/ AVC \/ MPEG-4 AVC \/ MPEG-4 part 10\",\r\n            \"profile\": \"Main\",\r\n            \"codec_type\": \"video\",\r\n            \"codec_time_base\": \"5\/299\",\r\n            \"codec_tag_string\": \"avc1\",\r\n            \"codec_tag\": \"0x31637661\",\r\n            \"width\": 960,\r\n            \"height\": 540,\r\n            \"coded_width\": 960,\r\n            \"coded_height\": 544,\r\n            \"has_b_frames\": 1,\r\n            \"sample_aspect_ratio\": \"1:1\",\r\n            \"display_aspect_ratio\": \"16:9\",\r\n            \"pix_fmt\": \"yuv420p\",\r\n            \"level\": 31,\r\n            \"color_range\": \"tv\",\r\n            \"color_space\": \"bt709\",\r\n            \"color_transfer\": \"bt709\",\r\n            \"color_primaries\": \"bt709\",\r\n            \"chroma_location\": \"left\",\r\n            \"refs\": 1,\r\n            \"is_avc\": \"true\",\r\n            \"nal_length_size\": \"4\",\r\n            \"r_frame_rate\": \"299\/10\",\r\n            \"avg_frame_rate\": \"299\/10\",\r\n            \"time_base\": \"1\/19136\",\r\n            \"start_pts\": 0,\r\n            \"start_time\": \"0.000000\",\r\n            \"duration_ts\": 574080,\r\n            \"duration\": \"30.000000\",\r\n            \"bit_rate\": \"1865648\",\r\n            \"bits_per_raw_sample\": \"8\",\r\n            \"nb_frames\": \"897\",\r\n            \"disposition\": {\r\n                \"default\": 1,\r\n                \"dub\": 0,\r\n                \"original\": 0,\r\n                \"comment\": 0,\r\n                \"lyrics\": 0,\r\n                \"karaoke\": 0,\r\n                \"forced\": 0,\r\n                \"hearing_impaired\": 0,\r\n                \"visual_impaired\": 0,\r\n                \"clean_effects\": 0,\r\n                \"attached_pic\": 0,\r\n                \"timed_thumbnails\": 0\r\n            },\r\n            \"tags\": {\r\n                \"language\": \"und\",\r\n                \"handler_name\": \"ISO Media file produced by Google Inc.\"\r\n            }\r\n        },\r\n        {\r\n            \"index\": 1,\r\n            \"codec_name\": \"aac\",\r\n            \"codec_long_name\": \"AAC (Advanced Audio Coding)\",\r\n            \"profile\": \"LC\",\r\n            \"codec_type\": \"audio\",\r\n            \"codec_time_base\": \"1\/44100\",\r\n            \"codec_tag_string\": \"mp4a\",\r\n            \"codec_tag\": \"0x6134706d\",\r\n            \"sample_fmt\": \"fltp\",\r\n            \"sample_rate\": \"44100\",\r\n            \"channels\": 2,\r\n            \"channel_layout\": \"stereo\",\r\n            \"bits_per_sample\": 0,\r\n            \"r_frame_rate\": \"0\/0\",\r\n            \"avg_frame_rate\": \"0\/0\",\r\n            \"time_base\": \"1\/44100\",\r\n            \"start_pts\": 0,\r\n            \"start_time\": \"0.000000\",\r\n            \"duration_ts\": 1323000,\r\n            \"duration\": \"30.000000\",\r\n            \"bit_rate\": \"91250\",\r\n            \"max_bit_rate\": \"128000\",\r\n            \"nb_frames\": \"1293\",\r\n            \"disposition\": {\r\n                \"default\": 1,\r\n                \"dub\": 0,\r\n                \"original\": 0,\r\n                \"comment\": 0,\r\n                \"lyrics\": 0,\r\n                \"karaoke\": 0,\r\n                \"forced\": 0,\r\n                \"hearing_impaired\": 0,\r\n                \"visual_impaired\": 0,\r\n                \"clean_effects\": 0,\r\n                \"attached_pic\": 0,\r\n                \"timed_thumbnails\": 0\r\n            },\r\n            \"tags\": {\r\n                \"language\": \"und\",\r\n                \"handler_name\": \"ISO Media file produced by Google Inc.\"\r\n            }\r\n        }\r\n    ]\r\n}\r\n<\/code><\/pre>\n<pre><code style=\"color: midnightblue; font-size: 12px; white-space: pre-wrap;\"><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>python \u3092 apache \u3067\u5b9f\u884c\u3059\u308b\u3053\u3068\u3092\u8a66\u3057\u3066\u3044\u307e\u3059\u3002php \u304b\u3089 py &#8230; <a class=\"more-link\" href=\"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/?p=10627\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10627","post","type-post","status-publish","format-standard","hentry","category-column"],"_links":{"self":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/10627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10627"}],"version-history":[{"count":53,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/10627\/revisions"}],"predecessor-version":[{"id":10765,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/10627\/revisions\/10765"}],"wp:attachment":[{"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10627"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zairyo.susi.oita-u.ac.jp\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}