我有一个使用YAML的Python程序.我尝试使用它在新服务器上安装它pip install yaml
,它返回以下内容:
$ sudo pip install yaml
Downloading/unpacking yaml
Could not find any downloads that satisfy the requirement yaml
No distributions at all found for yaml
Storing complete log in /home/pa/.pip/pip.log
Run Code Online (Sandbox Code Playgroud)
如何安装Python的yaml包?我正在运行Python 2.7.(操作系统:Debian Wheezy)
我的目标很简单:启动rsync并且不要等待.
Debian上的Python 2.7.9
示例代码:
rsync_cmd = "/usr/bin/rsync -a -e 'ssh -i /home/myuser/.ssh/id_rsa' {0}@{1}:'{2}' {3}".format(remote_user, remote_server, file1, file1)
rsync_cmd2 = "/usr/bin/rsync -a -e 'ssh -i /home/myuser/.ssh/id_rsa' {0}@{1}:'{2}' {3} &".format(remote_user, remote_server, file1, file1)
rsync_path = "/usr/bin/rsync"
rsync_args = shlex.split("-a -e 'ssh -i /home/mysuser/.ssh/id_rsa' {0}@{1}:'{2}' {3}".format(remote_user, remote_server, file1, file1))
#subprocess.call(rsync_cmd, shell=True) # This isn't supposed to work but I tried it
#subprocess.Popen(rsync_cmd, shell=True) # This is supposed to be the solution but not for me
#subprocess.Popen(rsync_cmd2, shell=True) # Adding my own shell "&" …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Paramiko 来打开(和维护)一个频道,以便我可以发出一些命令;但是,我无法找到使用 paramiko.Transport 和使用私钥的示例。我已经能够连接到我的服务器并使用以下代码运行命令:
ssh = paramiko.SSHClient()
paramiko.util.log_to_file("support_scripts.log")
private_key = paramiko.RSAKey.from_private_key_file(rsa_private_key)
ssh.connect(server, username=user, password='', pkey=private_key)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(cmd)
Run Code Online (Sandbox Code Playgroud)
没有问题。据我了解,这不会创建“交互式会话”,这意味着我无法发出cd /home/my_user/my_scripts
然后发出另一个命令,例如python script_in_my_scripts_folder.py
. 因此,我正在尝试使用 Paramiko Transport 对象,它可以帮助我维护一个交互式会话。搜索高低,我找到的例子都不适合我。现在,以下代码在第 204 行返回“SSHException: Channel is not open”,这是下面的 exec_command:
PRIVATEKEY = '/home/my_user/.ssh/id_rsa'
user = 'harperville'
server = '10.0.10.10'
port = 22
paramiko.util.log_to_file("support_scripts.log")
trans = paramiko.Transport((server,port))
rsa_key = paramiko.RSAKey.from_private_key_file(PRIVATEKEY)
trans.connect(username=user, pkey=rsa_key)
session = trans.open_channel("session")
session.exec_command('cd /home/harperville/my_scripts/')
Run Code Online (Sandbox Code Playgroud)
我理解它告诉我的内容的要点,但我无法找到或理解帮助我解决这个问题的文档。
提前致谢。
如果我尝试安装nokogiri,我收到以下错误:
rvmsudo gem install nokogiri
ERROR: Error installing nokogiri:
nokogiri requires Ruby version >= 1.9.2.
Run Code Online (Sandbox Code Playgroud)
如果我检查我的ruby版本,它会告诉我我正在运行ruby1.9.3
ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]
Run Code Online (Sandbox Code Playgroud)
如果我使用printenv
,这些是我的env变量:
rvm_bin_path=/home/jenkins/.rvm/bin
GEM_HOME=/home/jenkins/.rvm/gems/ruby-1.9.3-p448@nokogiri
SHELL=/bin/bash
TERM=xterm-color
IRBRC=/home/jenkins/.rvm/rubies/ruby-1.9.3-p448/.irbrc
HUSHLOGIN=FALSE
MY_RUBY_HOME=/home/jenkins/.rvm/rubies/ruby-1.9.3-p448
USER=jenkins
rvm_path=/home/jenkins/.rvm
L1=-
rvm_prefix=/home/jenkins
MAIL=/var/mail/jenkins
PATH=/home/jenkins/.rvm/gems/ruby-1.9.3-p448@nokogiri/bin:/home/jenkins/.rvm/gems/ruby-1.9.3-p448@global/bin:/home/jenkins/.rvm/rubies/ruby-1.9.3-p448/bin:/home/jenkins/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
PWD=/home/jenkins
LANG=C
rvm_version=1.21.3 (stable)
SHLVL=1
HOME=/home/jenkins
LOGNAME=jenkins
GEM_PATH=/home/jenkins/.rvm/gems/ruby-1.9.3-p448@nokogiri:/home/jenkins/.rvm/gems/ruby-1.9.3-p448@global
install_flag=1
RUBY_VERSION=ruby-1.9.3-p448
_=/usr/bin/printenv
Run Code Online (Sandbox Code Playgroud)
我对RVM运气不错,而不是打破我的整个装置,我想我会问这里.
为什么我不能继续安装nokogiri?
我在Debian上.
我在Python中使用'requests'模块来查询RESTful API端点.有时,端点返回HTTP错误500.我意识到我可以使用requests.status_code获取状态代码但是当我收到错误500时,我想看到HTTP"响应文本"(我不确定它叫什么,以下例子).到目前为止,我已经能够使用response.headers获取一些头文件.但是,我正在寻找的信息仍然不存在.
使用"curl -vvv",我可以看到我之后的HTTP响应(为清楚起见省略了一些输出):
< HTTP/1.1 200 OK <---------------------this is what I'm after)
* Server nginx/1.4.1 is not blacklisted
< Server: nginx/1.4.1
< Date: Wed, 05 Feb 2014 16:13:25 GMT
< Content-Type: application/octet-stream
< Connection: close
< Set-Cookie: webapp.session.id="mYzk5NTc0MDZkYjcxZjU4NmM=|1391616805|f83c47a363194c1ae18e"; expires=Fri, 07 Mar 2014 16:13:25 GMT; Path=/
< Content-Disposition: attachment; filename = "download_2014161325.pdf"
< Cache-Control: public
Run Code Online (Sandbox Code Playgroud)
再次,这是从卷曲.现在,当我使用Python的请求模块并询问标题时,这就是我得到的:
CaseInsensitiveDict(
{
'date': 'Tue, 04 Feb 2014 21:56:45 GMT',
'set-cookie': 'webapp.session.id="xODgzNThlODkzZ2U0ZTg=|1391551005|a11ca2ad11195351f636fef"; expires=Thu, 06 Mar 2014 21:56:45 GMT; Path=/,
'connection': 'close',
'content-type': 'application/json',
'server': 'nginx/1.4.1' …
Run Code Online (Sandbox Code Playgroud) 当我登录我的CentOS服务器时,我的~/.bashrc
文件正在被采购.这是显而易见的,因为1.)我有一条logger "sourcing ~/.bashrc"
消息~/.bash_profile
,我看到了这个消息/var/log/messages
; 2.)我的提示确实显示了我当前的工作目录,这是我的提示所特有的众多事情之一.
但是,当我进入Git仓库时,当前的Git分支没有显示:
(/home/jenkins/GitLab/testing-scripts/tests) jenkins-tests $
Run Code Online (Sandbox Code Playgroud)
当我在这个回购中时,如果我找到我的~/.bashrc
文件,我会看到我的Git分支,就像我预期的那样:
(/home/jenkins/GitLab/testing-scripts/tests) jenkins-tests $ . ~/.bashrc
(/home/jenkins/GitLab/testing-scripts/tests) jenkins-tests (devel)$
Run Code Online (Sandbox Code Playgroud)
如果我机会我的分支,为了显示当前分支,我必须source ~/.bashrc
再次.
我~/.bashrc
执行__git_ps1
从这里获取的公共命令.
我~/.bash_profile
包含以下内容:
GP=~/.git-prompt.sh
if [ -f $GP ]; then
. $GP;
logger "sourced $GP";
fi
BRC=~/.bashrc
if [ -f $BRC ]; then
. $BRC;
logger "sourced $BRC";
fi
BA=~/.bash_aliases
if [ -f $BA ]; then
. $BA;
logger "sourced $BA";
fi …
Run Code Online (Sandbox Code Playgroud) python ×4
python-2.7 ×2
bash ×1
centos ×1
debian ×1
git ×1
http-headers ×1
linux ×1
paramiko ×1
pip ×1
popen ×1
private-key ×1
pyyaml ×1
ruby ×1
rubygems ×1
rvm ×1
subprocess ×1
yaml ×1