小编Ham*_*daq的帖子

python 2.4中的服务器不支持SMTP AUTH扩展

这是我在我的VPS主机中提供python 2.4的常规代码

def mail(receiver,Message):
    import smtplib
    try:
        s=smtplib.SMTP()
        s.connect("smtp.gmail.com",465)
        s.login("email@gmail.com", "password")
        s.sendmail("email@gmail.com", receiver, Message)
    except Exception,R:
            return R
Run Code Online (Sandbox Code Playgroud)

但不幸的是返回此消息!: SMTP AUTH extension not supported by server.

在我安装python 2.7的计算机中,我找到了解决方案并且它的工作非常好,这里是这段代码:

def mail(T,M):
    import smtplib
    try:
        s=smtplib.SMTP_SSL()
        s.connect("smtp.gmail.com",465)
        s.login("xxxxx@gmail.com","your_password")
        s.sendmail("xxxxx@gmail.com", T, M)
    except Exception,R:
            print R
Run Code Online (Sandbox Code Playgroud)

但是在安装了python 2.4的VPS中没有SMTP_SSL()并返回此消息 'module' object has no attribute 'SMTP_SSL'

此外,我试图在VPS升级我的python,但发生的事情是损坏整个python,这意味着python根本不起作用.

python linux smtp vps python-2.4

13
推荐指数
1
解决办法
2万
查看次数

创建数组而不声明大小 - java

我正在挖掘同样的问题,但我找不到与我相同的问题

我想创建一个数组而不声明大小,因为我不知道它会是怎样的!

要清除这个问题,我想给你一些我正在寻找的代码

public class t
{
 private int x[];
 private int counter=0;
 public void add(int num)
 {
   this.x[this.counter] = num;
   this.counter++;
 }
}
Run Code Online (Sandbox Code Playgroud)

如您所见,用户可以使用该add函数将元素添加到数组10000次或仅一次,因此它的大小未知

java arrays size declare

13
推荐指数
2
解决办法
10万
查看次数

在python中使用mysql Connector插入数据

我遇到了一个有线问题,当我要将数据插入我的数据库时,它不会插入而不会失败(抛出异常)!,,当数据重复或提供错误的表时,它会抛出异常!

这是我的代码!

from mysql import connector
con = connector.Connect(user='root',password='root',database='test',host='localhost')
cur=con.cursor()
cur.execute("""insert into user values ('userName', 'passWord')""") 
Run Code Online (Sandbox Code Playgroud)

数据库test仅包括一个表,该表是users与包括3个字段,其是idusername并且password,用户名是唯一id是A_I

请注意 我也使用过此查询!:

""插入用户(username,password)值('userName','passWord');"""

尝试了很多方法,但没有发生任何事情(没有插入,也没有例外!)

python mysql insert mysql-connector

9
推荐指数
1
解决办法
6992
查看次数

在不执行类的情况下导入 - python

我的问题是我有一个包含类的文件,在这个类中有一堆代码将被执行

所以每当我导入该文件时,它都会执行!不创建类的对象!,这是例子

文件 X

class d:
    def __init__(self):
        print 'print this will NOT be printed'
    print "this will be printed"
Run Code Online (Sandbox Code Playgroud)

文件 B

import x
Run Code Online (Sandbox Code Playgroud)

output is this will be printed,所以我的问题是如何跳过执行它直到创建一个新对象?

python class object call python-2.7

5
推荐指数
1
解决办法
2885
查看次数

如何检查数组中的非零值(元素)

我想知道如何编写一个函数来返回是否至少有三个值不等于 0。我搜索过类似的问题,但找不到任何有效的解决方案。为了解释我的问题,这里有一个例子:

我有一个包含这些元素的数组: [1,0,2,0,4,0,0,3,0,0]。我想检查是否至少有 3 个元素不等于 0。

1如果至少有 3 个元素,我的代码将返回!= 00如果元素少于 3 个,我的代码将返回!=0

所以在我的例子中它应该返回1.

c arrays

4
推荐指数
1
解决办法
2万
查看次数

flask-restful如何获取GET参数

我想知道如何GET像他一样获取瓶子中的参数 /hi/city?=NY

我可以这样做/hi/city/NY使用/hi/city/<string:ccc>,但如何与这样做/hi/city?=NY.

我检查了文档,似乎使用reqparse:http://flask-restful.readthedocs.org/en/latest/reqparse.html但仍然无法弄清楚如何

flask flask-restful

4
推荐指数
2
解决办法
4993
查看次数

flask-restful with flask-auth:具有不同身份验证的多个HTTP方法

我正在尝试使用具有多个HTTP(GET,POST,PUT,DELETE)方法的相同URL,并且对于每个方法,它使用flask-auth进行不同的身份验证.

我尝试创建的不仅仅是类

class GetUser(Resource):


    decorators = [Users.auth.login_required]
    def get(self):
        '''..etc'''

class PostUser(Resource):


    decorators = [Admin.auth.login_required]
    def post(self):
        '''..etc'''

restful_api.add_resource(GetUser,'/User')
restful_api.add_resource(PostUser,'/User')
Run Code Online (Sandbox Code Playgroud)

但是会发生什么事情restful_api.add_resource(PostUser,'/User')会覆盖restful_api.add_resource(GetUser,'/User')

authentication flask python-2.7 flask-restful flask-httpauth

3
推荐指数
1
解决办法
1314
查看次数

在python中以一行动态打印字符串

我正在尝试在一行中打印字符串.

我找到了解决方案,但它们无法正常使用Windows.

我有文本文件包含名称,我想像这样打印它们

name=john然后将john更改为下一个名称并保持name=,我已经制作了这段代码,但是无法正常使用windows:

op = open('names.txt','r')
print 'name=',
for i in op.readlines():
    print '\r'+i.strip('\n')
Run Code Online (Sandbox Code Playgroud)

感谢您的时间

python printing command-line line

2
推荐指数
1
解决办法
2328
查看次数

在python中发送/接收文件UDP

我已经制作了这个发送/接收脚本,但我损坏了文件!我不知道为什么我会遇到这个问题!

发件人.py

#!/usr/bin/env python

from socket import *
import sys

s = socket(AF_INET,SOCK_DGRAM)
host =sys.argv[1]
port = 9999
buf =1024
addr = (host,port)

file_name=sys.argv[2]

f=open(file_name,"rb") 
data = f.read(buf)

s.sendto(file_name,addr)
s.sendto(data,addr)
while (data):
    if(s.sendto(data,addr)):
        print "sending ..."
        data = f.read(buf)
s.close()
f.close()
Run Code Online (Sandbox Code Playgroud)

接收器.py

#!/usr/bin/env python

from socket import *
import sys
import select

host="0.0.0.0"
port = 9999
s = socket(AF_INET,SOCK_DGRAM)
s.bind((host,port))

addr = (host,port)
buf=1024

data,addr = s.recvfrom(buf)
print "Received File:",data.strip()
f = open(data.strip(),'wb')

data,addr = s.recvfrom(buf)
try:
    while(data):
        f.write(data)
        s.settimeout(2) …
Run Code Online (Sandbox Code Playgroud)

python sockets udp file-transfer sender

2
推荐指数
2
解决办法
6万
查看次数

将列表传递给瓶子中的模板

我有一个列表,其中包含作为元组列表的帖子信息(列表由元组组成),但我面临着如何将其传递给瓶子中的模板的问题,我已经尝试了很多,并检查了 stackoverflow 中的大多数问题,我找不到一个好的且明确的问题。

这是我尝试过的:

@route('/v/:name')
def page_viwer(name):
    id=db.searchU('user', name)
    result=db.searchU_forG(id[0][0])
    if len(result)>0:#if we got posts 
        return template('v',post=result)
Run Code Online (Sandbox Code Playgroud)

这是v.tpl

<html>
%for post in res:
    %for id, title, dec, pic,not_needed in post:
        <h3>{{id}}</h3>
        <h3>{{title}}</h3>
        <h3>{{dec}}</h3>
        <h3>{{pic}}</h3>
        <br/>
%end
</html>
Run Code Online (Sandbox Code Playgroud)

当我尝试这个时,我收到错误 500 ...当我检查日志时,原因是:

%for id, title, dec, pic in post: TypeError: 'int' object is not iterable

python template-engine wsgi list bottle

2
推荐指数
1
解决办法
5610
查看次数

selenium找不到合适的方法(ExpectedCondition <WebElement>)

这是有线问题!我导入的项目是100%工作(几个月前),今天我用依赖项导入了它,并且存在一个问题 WebDriverWait

这是我的代码:

WebDriverWait driverWait = new WebDriverWait(driver, 10000);
driverWait.until(ExpectedConditions.presenceOfElementLocated(By.id("saveBut1")));//here's the issue
Run Code Online (Sandbox Code Playgroud)

这是错误:

no suitable method found for until(ExpectedCondition<WebElement>)
    method FluentWait.until(Predicate<WebDriver>) is not applicable
      (argument mismatch; ExpectedCondition<WebElement> cannot be converted to Predicate<WebDriver>)
    method FluentWait.<V>until(Function<? super WebDriver,V>) is not applicable
      (cannot infer type-variable(s) V
        (argument mismatch; ExpectedCondition<WebElement> cannot be converted to Function<? super WebDriver,V>))
  where V,T are type-variables:
    V extends Object declared in method <V>until(Function<? super T,V>)
    T extends Object declared in class FluentWait
Run Code Online (Sandbox Code Playgroud)

我使用Netbeans作为IDE,然后使用它导出项目(3个月前)

java selenium netbeans

2
推荐指数
1
解决办法
2750
查看次数

写作没有在python中关闭

我想写文本文件而不关闭,因为我不知道我会停止什么,我会解释漏洞问题

我已创建调用的文本resume.txt,因此在我的项目中的每个特定进程之后它将覆盖,resume.txt因此每次我的项目启动它都将检查该文件以了解最后的进程所以我的问题在每次编写后我必须关闭以应用它而我不要认为这很好,我认为有更好的解决方案

这段代码不起作用

wr = open('resume.txt','w')
login(usr,pas)
wr.write('login')
post(msg,con)
wr.write('post')
..so on 
Run Code Online (Sandbox Code Playgroud)

问题是如何在没有关闭的情况下编写,我不能wr.close在最后编写,因为它可能被用户终止或连接超时..等等

python io text overwrite python-2.7

-1
推荐指数
1
解决办法
1811
查看次数