Possible Duplicate:
how to write in stdout after to call a method (doing a system of notifications automatic (Iphone))可能重复:如何在调用方法后写入stdout(自动执行通知系统(Iphone))
I have the following script, that I want to execute automatically in a django app. The issue is that it keeps asking for user input.
我有以下脚本,我想在django应用程序中自动执行。问题是它不断要求用户输入。
I would like to know How to pass user input automatically? This is the script:
我想知道如何自动传递用户输入?这是脚本:
from apns import APNs, Payload
apns = APNs(use_sandbox=True, cert_file='cert.pem', key_file='key.pem')
# Send a notification
token_hex = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b87'
payload = Payload(alert="Hello World!", sound="default", badge=1)
my_pass_phrase = 'efisgbieafb3939bg93g238g4792gff9'
apns.gateway_server.send_notification(token_hex, payload)
The issue happens at the following line:
问题发生在以下行:
apns.gateway_server.send_notification(token_hex, payload)
The script asks: Enter PEM pass phrase: and waits for user input.
该脚本询问:输入PEM密码短语:并等待用户输入。
I would like to know how to pass the pass phrase automatically. Thanks in advance!
我想知道如何自动传递密码短语。提前致谢!
1 个解决方案
#1
1
Because you are using a library and probably don't have direct access to suppress the asking for user input, what you might have to do in the code that calls this script is use the pexpect
module to watch for specific patterns in the output, and then send input appropriately:
因为您正在使用库并且可能没有直接访问来禁止询问用户输入,所以在调用此脚本的代码中可能需要执行的操作是使用pexpect模块来监视输出中的特定模式,以及然后适当地发送输入:
http://pypi.python.org/pypi/pexpect-u/2.5.1
Examples here: http://www.noah.org/wiki/pexpect
这里的例子:http://www.noah.org/wiki/pexpect
Might be something like:
可能是这样的:
import pexpect
child = pexpect.spawn('myAPNscript.py')
child.expect('Enter PEM pass phrase:.*')
child.sendline('FOO')
#1
1
Because you are using a library and probably don't have direct access to suppress the asking for user input, what you might have to do in the code that calls this script is use the pexpect
module to watch for specific patterns in the output, and then send input appropriately:
因为您正在使用库并且可能没有直接访问来禁止询问用户输入,所以在调用此脚本的代码中可能需要执行的操作是使用pexpect模块来监视输出中的特定模式,以及然后适当地发送输入:
http://pypi.python.org/pypi/pexpect-u/2.5.1
Examples here: http://www.noah.org/wiki/pexpect
这里的例子:http://www.noah.org/wiki/pexpect
Might be something like:
可能是这样的:
import pexpect
child = pexpect.spawn('myAPNscript.py')
child.expect('Enter PEM pass phrase:.*')
child.sendline('FOO')