ホーム » Iwao の投稿 (ページ 20)

作者アーカイブ: Iwao

2025年2月
 1
2345678
9101112131415
16171819202122
232425262728  

カテゴリー

アーカイブ

ブログ統計情報

  • 106,310 アクセス


NAS VirtualBox に Win10 … できず

ASUSTOR NAS の VirtualBox で動作させている Win10 が不安定なので,VirtualBox 上にインストールから…


ASUSTOR NAS の VirtualBox で作成した vdi をコピーしてそれを指定すると,
VirtualBox error: rc=0x80bb0001 Cannot register the hard disk ‘/volume1/Public/VHD/DevA/DevA.vdi’ {f7577f3a-2c71-49bb-b349-5b6aa27133bd} because a hard disk ‘/root/VirtualBox VMs/DevA/DevA.vdi’ with UUID {f7577f3a-2c71-49bb-b349-5b6aa27133bd} already exists (0x80070057)
vdi コピーでエラー
コマンドプロンプトで,
Microsoft Windows [Version 10.0.18362.1016]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Iwao>cd %TMP%

C:\Users\Iwao\AppData\Local\Temp>"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands sethduuid B:\VHD\DevA\DevA.vdi
UUID changed to: 7bf3a9e5-06f0-4718-b8ed-c48322cc99f9

C:\Users\Iwao\AppData\Local\Temp>


コピーした vdi を選択して起動すると,
UUID {bee82a51-4b3e-4856-9d86-f035dee8bd25} of the medium ‘/volume1/Public/VHD/DevA/DevA.vdi’ does not match the value {7bf3a9e5-06f0-4718-b8ed-c48322cc99f9} stored in the media registry (‘/root/.config/VirtualBox/VirtualBox.xml’)
コピーした vdi を選択して起動するとエラー
検索 してわかりやすかったのが次の所.
https://katurakuno.xsrv.jp/Linux/LinuxMint/virtualbox/error.html
C:\Users\Iwao\AppData\Local\Temp>"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" internalcommands sethduuid B:\VHD\DevA\DevA.vdi 7bf3a9e5-06f0-4718-b8ed-c48322cc99f9
UUID changed to: 7bf3a9e5-06f0-4718-b8ed-c48322cc99f9

C:\Users\Iwao\AppData\Local\Temp>


VirtualBox 内でセットアップは起動するが,リモートデスクトップサーバとして動作させる方法がわからない.
AS5202T VirtualBox Win10 インストール
今までは既存の vdi を使用していたが,インストールからとなると NAS 本体に接続するしかないのか?
以前,一時的に仮想マシンが起動する前に RDP 接続できていた時があったが,どこかの設定なのか?
QNAP NAS の Virtualization Station は,ブラウザから操作が可能


2020/09/20
VirtualBox の更新があり?リモートデスクトップ接続 できるようになった.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

TS-253D セットアップ – 7

幾つかの気づいたことをメモ.


SSH 接続 して python3 が動作しない.
python 2.7 は起動する.
App Center で Python3 はインストールしてある.
はっきりわからないが,App Center でインストールしたものと SSH 接続してのものとは異なるみたい.
admin で入って opkg install python3 でインストール.
QNAP NAS に Python 3 インストール
これで SSH 接続でも可能になった.


python3 がインストールできない場合,その前に entware のインストールが必要.
https://dev.mish.work/wordpress/2020/08/29/ts253d-setup-3-opkg/


インストールされている PHP は 7.3.7 .
アップロードできるファイルサイズはデフォルトで十分.


zip , unzip , 7z , convert は入っている.

[Iwao@TS253D prt_text]$ tree /mnt/ext/opt/ImageMagick/usr/local/
/mnt/ext/opt/ImageMagick/usr/local/
└── sbin
    ├── composite
    ├── convert
    └── identify

1 directory, 3 files
[Iwao@TS253D prt_text]$      

iconv コマンドは入ってなさそうだが iconv API は使える.


2020/08/18 pip の追加.

[~] # opkg install python3-pip
Installing python3-pip (19.2.3-4) to root...
Downloading http://bin.entware.net/x64-k3.2/python3-pip_19.2.3-4_x64-3.2.ipk
Installing python3-pkg-resources (41.2.0-3) to root...
Downloading http://bin.entware.net/x64-k3.2/python3-pkg-resources_41.2.0-3_x64-3.2.ipk
Installing python3-setuptools (41.2.0-3) to root...
Downloading http://bin.entware.net/x64-k3.2/python3-setuptools_41.2.0-3_x64-3.2.ipk
Installing python-pip-conf (0.1-1) to root...
Downloading http://bin.entware.net/x64-k3.2/python-pip-conf_0.1-1_x64-3.2.ipk
Configuring python-pip-conf.
Configuring python3-pkg-resources.
Configuring python3-setuptools.
Configuring python3-pip.
[~] #          

QNAP NAS に Flask のインストール


https://jml.mish.work/various/nas/qnap-nas.html
https://jml.mish.work/various/nas.html

Is this 投稿 useful? Useful Useless 1 of 1 people say this 投稿 is useful.

TS-253D セットアップ – 6

以前調べた時は,Synology NAS と同様に面倒だと思ったが…


検索すると
QNAPにEntware-stdをインストールする
QNAP NAS  QKPG Store の登録
QNAP NAS  Entware-std のインストール

Microsoft Windows [Version 10.0.18362.1016]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Iwao>\\WDCloud\Public\Document\bat\ssh_ts253d.bat

C:\Users\Iwao>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l Iwao -p 22 ts253d
Iwao@ts253d's password:
[Iwao@TS253D ~]$ gcc
-sh: gcc: command not found
[Iwao@TS253D ~]$ opkg
-sh: opkg: command not found
[Iwao@TS253D ~]$ /opt/bin/opkg
opkg must have one sub-command argument
usage: opkg [options...] sub-command [arguments...]
where sub-command is one of:

Package Manipulation:
        update                  Update list of available packages
        upgrade <pkgs>          Upgrade packages
        install <pkgs>          Install package(s)
        configure <pkgs>        Configure unpacked package(s)
        remove <pkgs|regexp>    Remove package(s)
        flag <flag> <pkgs>      Flag package(s)
         <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)

...

 regexp could be something like 'pkgname*' '*file*' or similar
 e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'
[Iwao@TS253D ~]$ 
[Iwao@TS253D ~]$ /opt/bin/opkg install gcc
Installing gcc (7.4.0-5) to root...
Downloading http://bin.entware.net/x64-k3.2/gcc_7.4.0-5_x64-3.2.ipk
Installing zlib (1.2.11-3) to root...
Downloading http://bin.entware.net/x64-k3.2/zlib_1.2.11-3_x64-3.2.ipk
Collected errors:
 * wfopen: //opt/lib/opkg/info/zlib.control: Permission denied.
 * extract_archive: Cannot create symlink from ./opt/lib/libz.so to 'libz.so.1': Permission denied.
 * extract_archive: Cannot create symlink from ./opt/lib/libz.so.1 to 'libz.so.1.2.11': Permission denied.
 * wfopen: /opt/lib/libz.so.1.2.11: Permission denied.
 * pkg_write_filelist: Failed to open //opt/lib/opkg/info/zlib.list: Permission denied.
 * opkg_install_pkg: Failed to extract data files for zlib. Package debris may remain!
 * opkg_install_cmd: Cannot install package gcc.
 * opkg_conf_write_status_files: Can't open status file //opt/lib/opkg/status: Permission denied.
 * opkg_conf_write_status_files: Can't open status file /opt/tmp//opt/lib/opkg/status: Permission denied.
[Iwao@TS253D ~]$ 

QNAP NAS ssh 接続 opkg
QNAP NAS opkg install gcc
sudo -i としても入れない.方法がわからなかったので admin で入ることに.

C:\Users\Iwao>ssh -l Iwao ts253d
Iwao@ts253d's password:
[Iwao@TS253D ~]$ sudo -i
Password:
Iwao is not in the sudoers file.  This incident will be reported.
[Iwao@TS253D ~]$
[Iwao@TS253D ~]$
[Iwao@TS253D ~]$ exit
logout
Connection to ts253d closed.

C:\Users\Iwao>ssh -l admin ts253d
admin@ts253d's password:
[~] #
[~] #
[~] #
[/opt/bin] # opkg install gcc  
Installing gcc (7.4.0-5) to root...
Downloading http://bin.entware.net/x64-k3.2/gcc_7.4.0-5_x64-3.2.ipk
Installing zlib (1.2.11-3) to root...
Downloading http://bin.entware.net/x64-k3.2/zlib_1.2.11-3_x64-3.2.ipk
Installing libiconv-full (1.11.1-4) to root...
Downloading http://bin.entware.net/x64-k3.2/libiconv-full_1.11.1-4_x64-3.2.ipk
Installing libintl-full (0.19.8.1-2) to root...
Downloading http://bin.entware.net/x64-k3.2/libintl-full_0.19.8.1-2_x64-3.2.ipk
Installing libbfd (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/libbfd_2.27-1_x64-3.2.ipk
Installing libopcodes (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/libopcodes_2.27-1_x64-3.2.ipk
Installing objdump (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/objdump_2.27-1_x64-3.2.ipk
Installing ar (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/ar_2.27-1_x64-3.2.ipk
Installing binutils (2.27-1) to root...
Downloading http://bin.entware.net/x64-k3.2/binutils_2.27-1_x64-3.2.ipk
Configuring zlib.
Configuring libiconv-full.
Configuring libintl-full.
Configuring libbfd.
Configuring libopcodes.
Configuring objdump.
Configuring ar.
Configuring binutils.
Configuring gcc.
There are no *-dev packages in Entware(with few exceptions)!
Please install headers as described in the wiki:
https://github.com/Entware/Entware/wiki
[/opt/bin] # 

QNAP NAS admin opkg install gcc

https://jml.mish.work/index.php/various/nas/qnap-nas.html

Is this 投稿 useful? Useful Useless 1 of 1 people say this 投稿 is useful.

TS-253D セットアップ – 5

メール通知の設定.
QNAP NAS メール通知の設定


WordPress の設定.
QNAP NAS  WordPress
そのまま進めてしまうとエラー.
QNAP NAS データベース接続確立エラー
検索すると pnpMyAdmin を入れるみたい
https://www.qnap.com/ja-jp/how-to/knowledge-base/article/how-to-install-wordpress-on-qts-4-4/
QNAP NAS  phpMyAdmin
phpMyAdmin を起動して root / admin と入力しても入れない.
「コントロールパネル」-「アプリケーション」-「SQLサーバー」で有効にする必要がある.
またこの時 root のパスワードを指定する.
QNAP NAS  SQL サーバ  パスワード指定
phpMyAdmin で wordpress データベースの作成
QNAP NAS WordPress データベース設定
QNAP NAS  WordPress  ブログ情報の登録
QNAP NAS WordPress ダッシュボード


Joomla! の設定.ASUSTOR NAS の時と同様.
QNAP NAS Joomla!  サイトの設定
QNAP NAS Joomla!  データベース設定
QNAP NAS Joomla!  インストール
QNAP NAS Joomla!  言語のインストール
QNAP NAS Joomla!  コントロールパネル

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

TS-253D セットアップ – 4

Virtualization Station 3 のエクスポート.
先日作成した Win10 を VirtualBox などで開くためにエクスポート.
仮想マシンの下にある「エクスポート」ボタンを押して,*.ovf で「スタート」.
Virtualization Station 3 で ovf のエクスポート
18 GB の img で 40 分位かかった.出力された vmdk は 9 GB .
AS5202T の VirtualBox で「ファイル」-「仮想アプライアンスのインポート」.
ASUSTOR NAS VirtualBox 仮想アプライアンスのインポート
変換に 5 分位.
そのまま実行すると 0xc0000225 .
チップセットを「ICH9」,「I/O APIC を有効化」にチェック.
AS5202T VirtualBox の仮想マシンの設定
安定して動作はするが,どこかで間違えたみたいでネットワークがうまく機能しない.
AS5202T phpVirtualBox
PC の VirtualBox で読み込んでみたが,やはりネットワークがうまく動作していない.
PC の VirtualBox でもネットワークがうまくない


今度は VirtualBox のエクスポート.
PC の VirtualBox で「仮想アプライアンスのエクスポート」,AS5202T 上の DevX をエクスポート.50 分位.
VirtualBox 仮想アプライアンスのエクスポート
QNAP NAS Virtualization Station 3 で「VM のインポート」.20 分位.
TS-253D Virtualization Station 3 「VM のインポート」
最初うまく起動しなかった(実際は表示がうまくされていなかっただけ?).
「設定」-「ビデオ」-「タイプ」を「Cirrus」になっていたものを「VGA」に.
Virtualization Station 3 「設定」-「ビデオ」-「タイプ」を「VGA」に
これでうまくいった.VNC 接続も問題なし.
Virtualization Station 3  VNC 接続

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

TS-253D セットアップ – 3

他の NAS と同じ様に Google Drive から NAS へのコピー.
HBS 3 Hybrid Backup Sync を利用するみたいだが,いろいろな機能がくっついているので慣れるまでわかり難い.


「同期」-「今すぐ同期」で 3 種類の方法が選べる.
QNAP NAS HBS 3 同期の種類
Google Drive 上のファイルを NAS へコピーなので「一方向同期ジョブ」と思ったが,これは NAS のデータを Cloud にバックアップするためのものみたい.
「双方向同期ジョブ」を選択.
QNAP NAS HBS 3 双方向同期
「アクティブ同期ジョブ」の設定を見ると Google Drive から NAS への矢印になっている.
QNAP NAS HBS 3 アクティブ同期
やりたかったのはこっちの方.
また「アクション」は「ミラー」の方が目的に合っている.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

TS-253D セットアップ – 2

今回の NAS で一番気になっている Virtualization Station 3
ASUSTOR NAS にも同様の目的の VirtualBox がある が,再起動時の安定度があまり良くない
2020/09/21 ASUSTOR NAS VirtualBox は 6.1.12 になり安定している.


「Virtualization Station 3」-「VM の作成」.
Virtualization Station 3  VM の作成
「OK」で「自動インストール」のメッセージが表示される.
Virtualization Station 3 「自動インストール」の確認
ここは「キャンセル」(「自動インストール」ではうまくいかなかった).
Virtualization Station 3 Win10 インストール開始
Virtualization Station 3 Win10 インストール終了
あまり速くない?
Virtualization Station 3 QNAP Guest Tools のインストール
ブラウザで操作していたため動きが悪かったのかもしれない.VNC 接続だとそれほど気にならない.
「Guest Tools」のインストールでは「Ultra VNC」もインストール可能になっている.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

TS-253D セットアップ

QNAP NAS TS-253D のセットアップ.
先ず,メモリの取り付け.
マニュアル通り進めれば可能.
https://us1.qnap.com/Storage/TechnicalDocument/Storage/SMB%20NAS/TS-x53D/TS-x53D-UG-01-ja-JP.pdf
但し,指の太い人はかなり厳しい.ケースカバーを外した方が作業はしやすいと思う.
メモリの表裏が,斜めから見るためわかり難い.
純正の 4G であれば,もともと付いているものと同じ向き(チップが付いている側が下).
HDD は WD Blue 3TB をベイ 2 に入れた.


以降は 付属のマニュアル を見ながらの作業.
ケーブルなどの接続を行い,PC に Qfinder をインストール.
画面の指示に従って進めていった.
TS-253D NAS 名称などの設定
TS-253D  QTS ログイン画面
TS-253D リソースモニタ
取り付けたメモリもちゃんと認識している.


QTS に入っていろいろと操作はできるが,なんかおかしい.
Web サーバを有効にできるのに「File Station」で見ると Web フォルダがない.
ユーザは追加できるが,標準で見えるはずの共有フォルダがない.
SSH 接続すると Home ディレクトリがない様なメッセージ.
ここまでの操作と付属のマニュアルを比べると,ディスクの設定がなかった.
付属のマニュアルは古いのかもしれない.


QNAP セットアップ」で検索すると次の所があった.
https://unistar.jp/column/2899/
これを見ると RAID の設定などは QTS から行うようになった?
TS-253D  ボリューム作成ウィザード 要約
ちょっとわからなかったのが,ボリューム容量の設定.
デフォルトでは 3.63 TB に対して 715.66 GB となった.
「最大に設定」で良いと思うが,今回は仮のセットアップのためデフォルトのままとした.


パスワードの制限は「コントロールパネル」-「システム」-「セキュリティ」-「パスワードポリシー」にある.


https://jml.mish.work/various/nas/qnap-nas.html



2021/05/17 マニュアル類が更新されている.
https://www.qnap.com/ja-jp/download?model=ts-253d&category=documents

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

NAS 環境に Flask のインストール

先ず Debian 環境に Flask をインストール.
pip3 install Flask
Debian Flask インストール
サンプルの hello.py を実行,ブラウザで表示.
hello.py を実行して,ブラウザで表示


AS5202T でも同様に Flask をインストール.
pip3 install Flask
AS5202T に Flask のインストール
AS5202T で実行,表示


Synology NAS では pip のインストールから.
suto opkg install python-pip
suto opkg install python3-pip
Synology NAS に pip のインストール
Flask をインストールしてみたが …

Iwao@DS116:~/pyt_test/t_flask$ pip3 install Flask
Collecting Flask
  Using cached https://files.pythonhosted.org/packages/f2/28/2a03252dfb9ebf377f40fba6a7841b47083260bf8bd8e737b0c6952df83f/Flask-1.1.2-py2.py3-none-any.whl
Collecting click>=5.1 (from Flask)
  Using cached https://files.pythonhosted.org/packages/d2/3d/fa76db83bf75c4f8d338c2fd15c8d33fdd7ad23a9b5e57eb6c5de26b430e/click-7.1.2-py2.py3-none-any.whl
Collecting itsdangerous>=0.24 (from Flask)
  Using cached https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting Werkzeug>=0.15 (from Flask)
  Using cached https://files.pythonhosted.org/packages/cc/94/5f7079a0e00bd6863ef8f1da638721e9da21e5bacee597595b318f71d62e/Werkzeug-1.0.1-py2.py3-none-any.whl
Collecting Jinja2>=2.10.1 (from Flask)
  Using cached https://files.pythonhosted.org/packages/30/9e/f663a2aa66a09d838042ae1a2c5659828bb9b41ea3a6efa20a20fd92b121/Jinja2-2.11.2-py2.py3-none-any.whl
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10.1->Flask)
  Using cached https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz
    Complete output from command python setup.py egg_info:
    /opt/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'project_urls'
    /opt/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'include_package_data'
    /opt/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'python_requires'
    usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: -c --help [cmd1 cmd2 ...]
       or: -c --help-commands
       or: -c cmd --help

    error: invalid command 'egg_info'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-dsqn65uh/MarkupSafe/
Iwao@DS116:~/pyt_test/t_flask$ 

DS116 に Flask インストール ... エラー?


「 Command python setup.py egg_info faild with error code 1 」で検索 をかけると pip などが古いとある.
次の様にして pip などを更新.
sudo pip install –upgrade pip setuptools
Synology NAS の pip の更新と Flask のインストール

Is this 投稿 useful? Useful Useless 1 of 1 people say this 投稿 is useful.

Python から CPP の呼出し – 3

////////////////////////////////////////////////////////////////////
//	test_cpp.hpp
//
#pragma		once

#include	"_s_func.hxx"
#include	"_t_func.hxx"
#include	"_tdefine.hxx"

class	test_class	{
public:
			test_class	(LPCTSTR n)	{	name = n ;	std::tout<< name + _T("\t***") << std::endl ;	}
	virtual		~test_class	()      	{	          	std::tout<< name + _T("\t---") << std::endl ;	}
public:
	tstring		name ;
	} ;

inline	test_class*	get_test_class	(void)
{
	static	test_class	G_tc("G_test") ;
	return	&G_tc ;
	}

////////////////////////////////////////////////////////////////////
//	test_cpp.cpp
//
#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

int	_tmain	(int argc,TCHAR* argv[])
{
	_tsetlocale(LC_ALL,_T("")) ;
	test_class	tc(_T("local 1")) ;
	{
		test_class	tc(_T("local 2")) ;
		std::tout << _T("hello") << std::endl ;
		}
	{
		test_class*	gt = ::get_test_class() ;
		std::tout << gt->name << std::endl ;
		}
	return	0 ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ test_cpp.cpp -Wall
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ ./a.out
global  ***
local 1 ***
local 2 ***
hello
local 2 ---
G_test  ***
G_test
local 1 ---
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $
////////////////////////////////////////////////////////////////////
//	t_cpp.cpp
//
#include	<Python.h>

#include	"test_cpp.hpp"
#include	<clocale>
#include	<iostream>

test_class	tc(_T("global")) ;

static	PyObject*	local__	(PyObject* self, PyObject* args)
{
	test_class	tc(_T("local")) ;
	std::tout << tc.name << std::endl ;
	return	Py_None;
	}

static	PyObject*	global_	(PyObject* self, PyObject* args)
{
	test_class*	gt = ::get_test_class() ;
	std::tout << gt->name << std::endl ;
	return	Py_None;
	}

static	PyMethodDef			t_cpp_methods[] = {
	{	"local__",   	local__,	METH_NOARGS,	"local__"	},
	{	"global_",   	global_,	METH_NOARGS,	"global_"	},
	{	NULL								},
	} ;

static	struct	PyModuleDef	t_cpp = {
	PyModuleDef_HEAD_INIT,
	"t_cpp",
	"test cpp module",
	-1,
	t_cpp_methods
	} ;

PyMODINIT_FUNC	PyInit_t_cpp(void)
{
	return	PyModule_Create(&t_cpp) ;
	}
////////////////////////////////////////////////////////////////////
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ g++ t_cpp.cpp -Wall -fPIC -shared -o t_cpp.so -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import t_cpp
global  ***
>>> dir(t_cpp)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'global_', 'local__']
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test  ***
G_test
>>> t_cpp.global_()
G_test
>>> import t_cpp
>>> t_cpp.local__()
local   ***
local
local   ---
>>> t_cpp.global_()
G_test
>>> exit()
G_test  ---
global  ---
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/test_cpp $ 

Python から C++ 呼び出し時のコンストラクタ,デストラクタ

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から C の呼出し – 2

先日 Python から C を呼び出す関係を調べていて Synology NAS に Python.h がなかった.
検索 をかけると DSM「パッケージ センター」-「Python3」では python-dev が入ってないらしい.


次の様な手順で python-dev をインストール.
# sudo -i
# cd /var/services/homes/Iwao/
# source ./set_ds_inc.sh
# opkg install python-dev
# opkg install python3-dev
Synology NAS に python-dev のインストール
コンパイルで必要なファイルは次の所に入った.
/volume1/@entware-ng/opt/include/python3.6/Python.h
/volume1/@entware-ng/opt/include/python2.7/Python.h
Synology NAS で Python から C の呼出し


Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ g++ g3d_to.cpp -Wall -fPIC -o g3d_to.so -shared
g3d_to.cpp:9:20: fatal error: Python.h: No such file or directory

                    ^
compilation terminated.
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ g++ g3d_to.cpp -Wall -fPIC -o g3d_to.so -shared -I /volume1/@entware-ng/opt/include/python3.6/
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ ll
total 9568
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 10:29 .
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 09:50 ..
-rwxrwxrwx+ 1 Iwao users 3941375 May  7 18:03 3887.imo
-rwxrwxrwx+ 1 Iwao users 1241865 Jul  7 15:13 7801.imo
drwxrwxrwx+ 2 Iwao users    4096 Aug  5 10:29 bak
-rwxrwxrwx+ 1 Iwao users    1688 Aug  4 15:04 g3d_to.cpp
-rwxrwxrwx  1 Iwao users 2654136 Aug  5 10:29 g3d_to.so
-rwxrwxrwx+ 1 Iwao users    1644 Aug  7  2019 gons_to.cpp
-rwxrwxrwx  1 Iwao users 1931244 Aug  5 10:17 gons_to.out
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ python3
Python 3.6.2 (default, Jan 11 2018, 10:32:53)
[GCC 6.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import g3d_to
>>> dir(g3d_to)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'gons_to', 'load', 'save']
>>> g3d_to.load("./7801.imo")
>>> g3d_to.save("./7801.stl")
>>> g3d_to.save("./7801.ac")
>>>
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ ll
total 10252
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 10:31 .
drwxrwxrwx+ 3 Iwao users    4096 Aug  5 09:50 ..
-rwxrwxrwx+ 1 Iwao users 3941375 May  7 18:03 3887.imo
-rwxrwxrwx+ 1 Iwao users  438369 Aug  5 10:31 7801.ac
-rwxrwxrwx+ 1 Iwao users 1241865 Jul  7 15:13 7801.imo
-rwxrwxrwx+ 1 Iwao users  254784 Aug  5 10:31 7801.stl
drwxrwxrwx+ 2 Iwao users    4096 Aug  5 10:29 bak
-rwxrwxrwx+ 1 Iwao users    1688 Aug  4 15:04 g3d_to.cpp
-rwxrwxrwx  1 Iwao users 2654136 Aug  5 10:29 g3d_to.so
-rwxrwxrwx+ 1 Iwao users    1644 Aug  7  2019 gons_to.cpp
-rwxrwxrwx  1 Iwao users 1931244 Aug  5 10:17 gons_to.out
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ 

DS116 で Python から C++ の呼出し
コンパイル,実行など AS5202T より時間がかかる.


https://jml.mish.work/python/call-c-python.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から CPP の呼出し – 2


予めデータ(vv_PLF)を作成して,必要に応じてファイルに出力するコード.

vv_PLF*	get_vv_PLF	(void)
{
	static	vv_PLF	G_PLF ;
	return	&G_PLF ;
	}
static	PyObject*	check_rd	(PyObject* self, PyObject* args)
{
	vv_PLF*	gvv_plf = get_vv_PLF() ;
	vv_PLF	vv_plf_ = ::Check_Revise_deg() ;
	*gvv_plf = vv_plf_ ;
	return	Py_None ;
	}
static	PyObject*	dump_svg	(PyObject* self, PyObject* args)
{
	vv_PLF*	gvv_plf = get_vv_PLF() ;
	::Dump_SVG(*gvv_plf) ;
	return	Py_None ;
	}
static	PyObject*	dump_ipl	(PyObject* self, PyObject* args)
{
	vv_PLF*	gvv_plf = get_vv_PLF() ;
	::Dump_ipl(*gvv_plf) ;
	return	Py_None ;
	}

Python から C++ の呼出し 複数のメソッドで共通な領域を使用する
Python 側では
* check_rd でデータを作成.
* dump_svg などでデータを出力.


3D データを読み込んで,指定されたファイル名(拡張子により形式を判断)で出力.

static	PyObject*	load	(PyObject* self, PyObject* args)
{
	const	char*	str_file = NULL ;
	if (!PyArg_ParseTuple(args,"s",&str_file))	{
		return	NULL ;
		}
	tstring	g3_file = str_file ;
	GonsA	gnsa = ::To_GonsA(g3_file.c_str()) ;
	set_GonsA(gnsa) ;
	return	Py_None;
	}
static	PyObject*	save	(PyObject* self, PyObject* args)
{
	const	char*	str_file = NULL ;
	if (!PyArg_ParseTuple(args,"s",&str_file))	{
		return	NULL ;
		}
	tstring	g3_file = str_file ;
	GonsA*	gnsa = ::get_GonsA() ;
	::GonsA_To(*gnsa,g3_file.c_str()) ;
	return	Py_None;
	}
static	PyObject*	gons_to	(PyObject* self, PyObject* args)
{
	const	char*	str_file = NULL ;
	if (!PyArg_ParseTuple(args,"s",&str_file))	{
		return	NULL ;
		}
	tstring	g3_file = str_file ;
	gons_to(g3_file.c_str()) ;
	return	Py_None;
	}

Python から C++ の呼出し 3D データの変換

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から CPP の呼出し

雰囲気はつかめてきたので,以前作成した cpp を呼んでみることに…
実際の処理部分は C++ のコードだが,呼び出しは C の関数.
また引数もない状態なので,C 関数の system(“a.out”) と呼んでいるのと同様.

#include	"i_rd_dbg.hxx"
int _tmain(int argc, TCHAR* argv[])
{
	::Test_Revise_deg() ;
	return 0 ;
	}

#include	<Python.h>
#include	"i_rd_dbg.hxx"
#include	"messbar.cxx"

static	PyObject*	call_cpp(PyObject* self, PyObject* args)
{
	::Test_Revise_deg() ;
	return	Py_None ;
	}

static	PyMethodDef 	 	myMethods[] = {
	{	"_call_cpp_",	call_cpp,	METH_NOARGS,	"call cpp"		},
	{	NULL														},
	} ;

static	struct	PyModuleDef	call_mod = {
	PyModuleDef_HEAD_INIT,
	"call_mod",
	"call_cpp module",
	-1,
	myMethods
	} ;

PyMODINIT_FUNC	PyInit_call_mod(void)
{
	return	PyModule_Create(&call_mod) ;
	}

コンパイルして import まではできたが,メソッドをうまく呼び出せない.
>>> call_mod.call_cpp()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module ‘call_mod’ has no attribute ‘call_cpp’
>>>
それで,メソッドを表示できないかと思い検索すると,
python でメソッドの一覧を取得する方法
他に dir(call_mod) もあった.

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc $ g++ rvs_sc_w.cpp -o call_mod.so  -fPIC -Wall -shared -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc $
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import call_mod
>>> call_mod.call_cpp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'call_mod' has no attribute 'call_cpp'
>>> call_mod.call_cpp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'call_mod' has no attribute 'call_cpp'
>>> obj = call_mod
>>> import inspect
>>> for m in inspect.getmembers(obj):
...     print(m)
...
('__doc__', 'call_cpp module')
('__file__', '/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc/call_mod.so')
('__loader__', <_frozen_importlib_external.ExtensionFileLoader object at 0x7f5a1a35ec50>)
('__name__', 'call_mod')
('__package__', '')
('__spec__', ModuleSpec(name='call_mod', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7f5a1a35ec50>, origin='/volume1/home/Iwao/test/test_py/call_c/call_cpp/T_Rvs_sc/call_mod.so'))
('_call_cpp_', <built-in function _call_cpp_>)
>>> call_mod._call_cpp_()
>>>

Python から cpp の呼出し メソッドの表示

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

ASUSTOR NAS に SSH 接続できない

AS5202T に SSH 接続 しようとすると,次のメッセージが表示されて接続できなくなった.
ssh_exchange_identification: read: Connection reset

Microsoft Windows [Version 10.0.18362.959]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Iwao>ssh -l Iwao 192.168.1.75
ssh_exchange_identification: read: Connection reset

C:\Users\Iwao>ssh -l Iwao as5202t
Password:
Iwao@AS5202T:/volume1/home/Iwao $ exit
Connection to as5202t closed.

C:\Users\Iwao>ssh -l Iwao 192.168.1.75
Password:
Iwao@AS5202T:/volume1/home/Iwao $ exit
Connection to 192.168.1.75 closed.

C:\Users\Iwao>ssh -l Iwao 192.168.1.75
Password:
Password:
Password:
Iwao@192.168.1.75's password:
Connection closed by 192.168.1.75 port 22

C:\Users\Iwao>ssh -l Iwao 192.168.1.75
ssh_exchange_identification: read: Connection reset

C:\Users\Iwao> 

AS5202T に SSH 接続できなくなった


対応方法:
ADM に入って「設定」-「ADMディフェンダー」の「自動ブラックリスト」で「削除」する.
ADM 「設定」-「ADMディフェンダー」
スマートフォンの「AiMaster」では「オンラインユーザー」-「ブラックリスト」から.
AiMaster 「オンラインユーザー」-「ブラックリスト」

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

WinFile.exe v10.1.4.0

Win10 環境で 2019/05 から使っている WinFile
最近よく操作する「ファイル」-「リネーム」がかなりの確率でダウンする(エラーなどは表示されず抜ける).


ダウンロード先を見てみると新しいものがあった.
https://github.com/Microsoft/winfile/releases
WinFile.exe v10.1.4.0


「リネーム」でダウンするのは相変わらず.

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python から C の呼出し

C のコードを Python から呼出せないかと…
Python のドキュメントとしては次の所にある
C や C++ による Python の拡張

Win10      C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\include\Python.h
debian10   /usr/include/python3.7/Python.h
AS5202T    /volume1/.@plugins/AppCentral/python3/include/python3.7m/Python.h

Iwao@AS5202T:/volume1/.@plugins/AppCentral/python3/include/python3.7m $ find / -name Python.h
/volume1/.@plugins/AppCentral/linux-center/containers/debian10/rootfs/usr/include/python2.7/Python.h
/volume1/.@plugins/AppCentral/linux-center/containers/debian10/rootfs/usr/include/python3.7m/Python.h
/volume1/.@plugins/AppCentral/python/include/python2.7/Python.h
/volume1/.@plugins/AppCentral/python3/include/python3.7m/Python.h

検索 して見つけたもの.
https://www.fsi-embedded.jp/kumico/columns/?cat=python
https://qiita.com/donkonishi/items/b7825b34d0711e336c61
https://www.quark.kj.yamagata-u.ac.jp/~hiroki/python/?id=19
http://owa.as.wakwak.ne.jp/zope/docs/Python/BindingC/
https://cpp-learning.com/?s=”Python+C+API”


Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $ cat hellWrap.c
#include <Python.h>
extern int add(int, int);
extern void out(const char*, const char*);

PyObject* hello_add(PyObject* self, PyObject* args)
{
    int x, y, g;

    if (!PyArg_ParseTuple(args, "ii", &x, &y))
        return NULL;
    g = add(x, y);
    return Py_BuildValue("i", g);
}

PyObject* hello_out(PyObject* self, PyObject* args, PyObject* kw)
{
    const char* adrs = NULL;
    const char* name = NULL;
    static char* argnames[] = {"adrs", "name", NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kw, "|ss",
            argnames, &adrs, &name))
        return NULL;
    out(adrs, name);
    return Py_BuildValue("");
}

static PyMethodDef hellomethods[] = {
    {"add", hello_add, METH_VARARGS},
    {"out", hello_out, METH_VARARGS | METH_KEYWORDS},
    {NULL}
};

void initchello(){
  Py_InitModule("hello", hellomethods);
}

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $ gcc -fPIC -Wall -c -o hellWrap.o hellWrap.c -I /volume1/.@plugins/AppCentral/python/include/python2.7/
hellWrap.c:30:13: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]
     {"out", hello_out, METH_VARARGS | METH_KEYWORDS},
             ^~~~~~~~~
hellWrap.c:30:13: note: (near initialization for 'hellomethods[1].ml_meth')
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $ gcc -fPIC -Wall -c -o hellWrap.o hellWrap.c -I /volume1/.@plugins/AppCentral/python/include/python2.7/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello/bak $   

Python から C の呼出し ラッパー
PyMethodDef の所でエラーとなっていていろいろと探すと,型を指定しているものがあり,それを指定.
https://bty.sakura.ne.jp/wp/archives/83

static PyMethodDef hellomethods[] = {
    {"add", (PyCFunction)hello_add, METH_VARARGS},
    {"out", (PyCFunction)hello_out, METH_VARARGS | METH_KEYWORDS},
    {NULL}
};

コンパイルは通る様になった.
Python から試そうとすると …

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ gcc -fPIC -Wall -c -o helloWrap.o helloWrap.c -I /volume1/.@plugins/AppCentral/python/include/python2.7/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ gcc -fPIC -Wall -shared -o hellomodule.so hello.o helloWrap.o
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ ll
total 44
drwxrwxrwx    3 Iwao     users       4.0K Jul 29 18:16 ./
drwxrwxrwx    5 Iwao     users       4.0K Jul 29 15:31 ../
drwxrwxrwx    2 Iwao     users       4.0K Jul 29 18:05 bak/
-rwxrwxrwx    1 Iwao     users        188 Jul 29 16:29 hello.c*
-rw-r--r--    1 Iwao     users       1.6K Jul 29 16:33 hello.o
-rwxrwxrwx    1 Iwao     users        910 Jul 29 16:32 helloWrap.BAK*
-rwxrwxrwx    1 Iwao     users        936 Jul 29 16:37 helloWrap.c*
-rw-r--r--    1 Iwao     users       3.1K Jul 29 18:16 helloWrap.o
-rwxr-xr-x    1 Iwao     users       8.3K Jul 29 18:16 hellomodule.so*
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'hello'
>>> exit()
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $ python
Python 2.7.10 (default, Aug 19 2015, 09:18:54)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hello
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (inithello)
>>> exit()
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/hello $   

Python から C の呼出し import でエラー
まだ何か違うみたい.
メッセージは inithello がないとなっているので helloWrap.c を見直すと…
void initchello() { … } となっている.
関数名を inithello に変更してビルドすると通った.
Python から C の呼出し


2020/07/30
今日は次の所を参考にさせてもらって…
https://cpp-learning.com/python_c_api_step1/

Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ gcc ph_hello.c -o mymodule.so -fPIC -Wall -shared -I /volume1/.@plugins/AppCentral/python3/include/python3.7m/
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mymodule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_mymodule)
>>> import myModule
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'myModule'
>>>
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ cp mymodule.so myModule.so
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ ll
total 44
drwxrwxrwx    3 Iwao     users       4.0K Jul 30 16:49 ./
drwxrwxrwx    6 Iwao     users       4.0K Jul 30 14:59 ../
drwxrwxrwx    2 Iwao     users       4.0K Jul 30 16:48 bak/
-rwxr-xr-x    1 Iwao     users       8.1K Jul 30 16:49 myModule.so*
-rwxr-xr-x    1 Iwao     users       8.1K Jul 30 16:47 mymodule.so*
-rwxrwxrwx    1 Iwao     users        188 Jul 29 16:29 ph_hello.BAK*
-rwxrwxrwx    1 Iwao     users       1.3K Jul 30 16:27 ph_hello.c*
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $ python3
Python 3.7.0 (default, Aug 23 2018, 17:48:39)
[GCC 4.6.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import myModule
>>> myModule.helloworld
<built-in function helloworld>
>>> myModule.helloworld()
Hello World
>>>
>>>
>>>
>>>
Iwao@AS5202T:/volume1/home/Iwao/test/test_py/call_c/py_hello $

Python から C の呼出し  py_hello
コンパイル時の出力ファイル名 mymodule.so が間違っていた.正しくは myModule.so .


そこ には詳しく書かれているが,自分用にメモ.
PyMethodDef の “メソッド名” は Python 側での (モジュール名).(メソッド名) .
同様に PyModuleDef の “モジュール名” は import 時の名称..so の出力ファイル名も対応している必要がある?
文字列なので,異なっていてもコンパイル時のエラーにはならない.
実行時に見つからないなどのエラーとなる.


2020/07/31
続きの内容をやっていて…
https://cpp-learning.com/python_c_api_step2/
Python から C の呼出しでエラー
Fatal Python error: GC object already tracked
Python から C の呼出し  Py_DECREF をコメントに
c_list は Python 側で確保しているため Py_DECREF はうまくないのではないか?


https://jml.mish.work/python/call-c-python.html

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Win10 IP 20H2 KB4568831

Win10 Insider Preview の環境に KB4568831 を入れてみた.
Win10 IP 20H2 KB4568831
あまり変わった部分がわからない…
Win10 IP 20H2 19042.421

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

CHttpFile アップロードの https 対応

以前作成した MFC によるアップロード の https 対応.
前回コードを書いた頃は https の環境が用意できなかったのでそのままと(http に)なっていた.


次の関数を呼び出して接続しているが,それぞれ引数が異なるものが用意されている.
CInternetSession::GetHttpConnection
CHttpConnection::OpenRequest
それらの引数に dwFlags があり,INTERNET_FLAG_SECURE が指定できる.
最初,両方の呼び出しに指定してみたが,CInternetSession::GetHttpConnection は指定しなくても通った.

	CInternetSession session(userAgent.c_str()) ;
	CHttpConnection* pServer = NULL ;
	CHttpFile*       pFile = NULL ;
	{
	//	if (is_ssl) {
	//		pServer = session.GetHttpConnection(serverN.c_str(),INTERNET_FLAG_SECURE,nPort) ;
	//		}
	//	else {
			pServer = session.GetHttpConnection(serverN.c_str(),nPort) ;
	//		}
		if (pServer == NULL)		{	return	false ;		}
		}
	{
		if (is_ssl) {
			pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,php,NULL,1,NULL,_T("HTTP/1.1"),INTERNET_FLAG_SECURE) ;
			}
		else {
			pFile = pServer->OpenRequest(CHttpConnection::HTTP_VERB_POST,php) ;
			}
		if (pFile == NULL)		{	return	false ;		}
	//	...
		}

MFC を使用したアップロード  https post
UpFile.hxx


参考にさせてもらったのは次の所.
How to send HTTPS request using WinInet?
WinInet(MFC)を使ったhttpとhttps(自己証明書)
WinInet (MFC) の SSL通信 で 開発中に自己署名証明書を利用する場合のコード

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

アップロードがうまく機能しない?

個人的なメモです.


php と form でアップロードしていた所に,汎用のアップロードツール で行うとうまく機能しない.
http://ds116/Test/mics/mba_wgl/


原因は,php の post を受け取って $_FILES を処理している所.
$tempfile = $_FILES[‘fname’][‘tmp_name’] ;
<input type="file" name="fname" accept=".dat">
https://dev.mish.work/wordpress/2018/04/19/php-_files/
これとアップロードツールの C のコード ::Make_send_data で設定している名称が合っていない.


php の受け取る部分を修正して意図した動作になった.
アップロードがうまく機能しない?

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

Python 負のインデックス

次の所を読ませてもらっていて感じたことを…
けいしゅけのブログ薬局 情報館
https://keisyuke-blogyakkyoku.xyz/python-list-index
今私が習得するのにタイミングや更新サイクルが丁度良いので助かっている.


ASUSTOR NAS AS5202T に SSH 接続して Python を操作.

C:\Program Files\Microsoft Office\Office14>cd C:\Users\Iwao\AppData\Local\Temp

C:\Users\Iwao\AppData\Local\Temp>ssh -l Iwao -p 22 192.168.1.75
Password:
Iwao@AS5202T:/volume1/home/Iwao $ python
Python 2.7.10 (default, Aug 19 2015, 09:18:54)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[0,1,2,3,4]
>>> print(a[0])
0
>>> print(a[4])
4
>>> print(a[5])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>> print(a[-1])
4
>>> print(a[-4])
1
>>> print(a[-5])
0
>>> print(a[-6])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: list index out of range
>>>  

Python 負のインデックス
似たようなことを C++ でやろうとすると次の様な感じ.
std::cout << a[a.size()-1] ;


この様な記述ができるからか,今まで負のインデックスの必要性は感じたことがなかった.
また配列の検索で該当するものがないと -1 を返す様なコードもよく書く.
インデックスを変数で持つ時は?
いろいろ考えると個人的にはあまり使わないのではないかと思う.
Python などをやればもっと有効な使い方が出てくるのか?

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.