我在CentOS 6服务器上设置了nginx和uwsgi。当我将某些数据发布到Web服务器时,它会被正确处理,但不会返回任何输出。如果我在应用程序函数返回之前在应用程序之前打印生成的html,则HTML在控制台中显示正确,但是控制台上的下一行是:
[pid: 31650|app: 0|req: 2/2] <server ip> () {48 vars in 873 bytes} [Mon Sep 15 18:19:45 2014] POST / => generated 0 bytes in 10583 msecs (HTTP/1.1 200) 1 headers in 44 bytes (418 switches on core 0)
Run Code Online (Sandbox Code Playgroud)
我增加了套接字超时时间,但没有任何区别。
编辑:我为此提出了一个奇怪的解决方法。我的html被存储在变量“ html”中。我从以下位置更改了代码:
return [html] #This would not return any output even though 'print html' was fine
Run Code Online (Sandbox Code Playgroud)
至:
open('/tmp/ot.txt', 'w').write(html)
d = open('/tmp/ot.txt').read()
return [d] #This works!
Run Code Online (Sandbox Code Playgroud)
我宁愿不使用我的解决方法。任何想法,为什么这是可行的和原始的无效。Python版本是2.6.6
我想创建一个像这样的数组 [1, 1, 1, 1, 1]
在python我可以使用 myarray = [1]*5
在PHP中是否存在等效方法,或者我必须在循环中添加所有元素.
我正在使用Python向gmail帐户发送电子邮件.这是我正在使用的代码
msg = email.mime.multipart.MIMEMultipart()
msg['From'] = 'myemail@gmail.com'
msg['To'] = 'toemail@gmail.com'
msg['Subject'] = 'HTML test'
msg_html = email.mime.text.MIMEText('<html><head></head><body><b>This is HTML</b></body></html>', 'html')
msg_txt = email.mime.text.MIMEText('This is text','plain')
msg.attach(msg_html)
msg.attach(msg_txt)
#SNIP SMTP connection code
smtpConn.sendmail('myemail@gmail.com', 'toemail@gmail.com', msg.as_string())
Run Code Online (Sandbox Code Playgroud)
当我在Gmail中查看此电子邮件时,HTML和文本版本都显示如下:
这是HTML
这是文字
它应该是显示文本还是html,导致此行为的原因.
我正试图<ul>从python中的网页获取标签的内容.我使用了以下代码:
matchResult = re.search(r'<ul\s*content="MSL">(.*)</ul>', queryResult, re.MULTILINE)
这不起作用.但是,如果我通过使用
queryResult = queryResult.replace('\r','').replace('\n','')
它删除换行符.
PHP中的这个正则表达式工作正常而不删除换行符:
preg_match('@<ul\s*content="MSL">(.*)</ul>@msU', $queryResult, $matches);
如何使用Python匹配多行?
我正在尝试扩展C#List以使用Print功能.使用Console.WriteLine(a.Print())只显示部分输出,但a.Print2()正常工作,其中在a.Print我打电话返回类型为字符串,并以a.Print2我打电话用的功能的方法返回值无效.
using System;
using ExtensionMethods;
using System.Collections.Generic;
namespace ExtensionMethods
{
public static class ExtensionClass
{
public static int PlusFive(this int input)
{
return input + 5;
}
static public string Print(this List<int> input)
{
int i;
string output = "";
for (i = 0; i < input.Count - 1; i++)
{
output = input[i].ToString() + ", ";
}
output += input[i].ToString();
return output;
// Outputs 2, 3
}
static public void Print2(this List<int> input)
{
int i;
for (i = …Run Code Online (Sandbox Code Playgroud)