标签: attributeerror

Python套接字超时错误

我在Python 2.7中编写了一个非常简单的udp套接字连接

服务器端已启动并正在运行.我在客户端遇到麻烦.

from socket import *

serverName = '127.0.0.1'
serverPort = 5444
counter = 1;

while counter < 55:
    mySocket = socket(AF_INET,SOCK_DGRAM)

    try:
        mySocket.settimeout(1.0)
        message = raw_input('')
        mySocket.sendto(message,(serverName, serverPort))
        modifiedMessage, serverAddress = mySocket.recvfrom(1024)
    except mySocket.timeout:
        print 'Request timed out!'
        mySocket.close()
    else:   
        print 'Server Response:  '
        print modifiedMessage   

    mySocket.close()
Run Code Online (Sandbox Code Playgroud)

我收到以下错误.除了mySocket.timeout:AttributeError:'_ socketocket'对象没有属性'timeout'

我无法理解为什么没有超时属性?!

事实上,我正在看知识分子,也没有这样的属性.

任何建议将不胜感激

python attributes timeout attributeerror

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

"队列"对象没有属性"大小"

我在StackOverflow上看到过这种情况的其他例子,但是我不理解任何答案(我还是一个新程序员),我看到的其他例子看起来也不像我的,否则我不会发布这个题.

我在Windows 7上运行Python 3.2.

我之前从来没有遇到这种情况,而且我已经多次这样做过课,所以这次我真的不知道有什么不同.唯一的区别是我没有制作所有的Class文件; 我得到了一个填写的模板和一个测试文件来试试.它适用于测试文件,但不能处理我的文件.我一直在以与测试文件完全相同的方式调用类中的方法(例如Lineup.size())

这是我的班级:

class Queue:

    # Constructor, which creates a new empty queue:
    def __init__(self):
        self.__items = []

    # Adds a new item to the back of the queue, and returns nothing:
    def queue(self, item):
        self.__items.insert(0,item)
        return

    # Removes and returns the front-most item in the queue.  
    # Returns nothing if the queue is empty.
    def dequeue(self):
        if len(self.__items) == 0:
            return None
        else:
            return self.__items.pop()

    # Returns the front-most item in the queue, and DOES …

python queue class attributeerror python-3.x

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

'datetime.datetime'对象没有属性'microseconds'

我在python中编写脚本,我需要知道代码中两点之间有多少毫秒.

程序启动时我有一个全局变量:

from datetime import datetime
a=datetime.now()
Run Code Online (Sandbox Code Playgroud)

当我需要知道已经过了多少毫秒时,我执行这个:

  b=datetime.now()
  print (b.microseconds-a.microseconds)*1000
Run Code Online (Sandbox Code Playgroud)

但是我收到此错误:

AttributeError: 'datetime.datetime' object has no attribute 'microseconds'
Run Code Online (Sandbox Code Playgroud)

怎么了?我怎样才能解决这个问题?

python error-handling datetime attributeerror

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

尝试使用tkFont时的AttributeError

当我运行此代码时:

from Tkinter import *
import tkFont

class Statify():

    def __init__(self):

        ### Broken
        self.titleFont = tkFont.Font(family='Helvetica', size=24, weight='bold')
        self.option_add(*Label*font, self.titleFont)
        ###

        self.root = Tk()
        self.root.withdraw()
        self.main = Toplevel(self.root)
        self.main.title('')
        self.main_header = Frame(self.main)
        self.main_footer = Frame(self.main)
        self.main_title = Label(self.main_header, text='Statify Me v1.0 (WIP)')
        self.main_exit = Button(self.main_footer, text='Quit', command=quit)
        self.main_header.pack()
        self.main_footer.pack()
        self.main_title.pack()
        self.main_exit.pack()
        mainloop()

statify = Statify()
Run Code Online (Sandbox Code Playgroud)

我明白了:

Traceback (most recent call last):
  File "Statify.py", line 23, in <module>
    statify = Statify()
  File "Statify.py", line 7, in __init__
    self.titleFont = tkFont.Font(family='Helvetica', size=24, …
Run Code Online (Sandbox Code Playgroud)

python fonts tk-toolkit tkinter attributeerror

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

AttributeError:'builtin_function_or_method'对象没有属性'replace'

当我尝试在我的程序中使用它时,它表示存在属性错误

'builtin_function_or_method' object has no attribute 'replace'
Run Code Online (Sandbox Code Playgroud)

但我不明白为什么.

def verify_anagrams(first, second):
    first=first.lower
    second=second.lower
    first=first.replace(' ','')
    second=second.replace(' ','')
    a='abcdefghijklmnopqrstuvwxyz'
    b=len(first)
    e=0
    for i in a:
        c=first.count(i)
        d=second.count(i)
        if c==d:
            e+=1
    return b==e
Run Code Online (Sandbox Code Playgroud)

python string attributeerror

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

Python smtplib send_message()失败,返回AttributeError:'str'对象没有属性'get_all'

我正在开发一个项目,我必须使用Python 3.4中的smtplib和email模块发送电子邮件.

我能够自己创建电子邮件,我可以连接到服务器,但它会返回此异常:

reply: b'235 2.7.0 Accepted\r\n'
reply: retcode (235); Msg: b'2.7.0 Accepted'
send: 'QUIT\r\n'
reply: b'221 2.0.0 closing connection s66sm8304113yhp.2 - gsmtp\r\n'
reply: retcode (221); Msg: b'2.0.0 closing connection s66sm8304113yhp.2 - gsmtp'
Traceback (most recent call last):
  File "base.py", line 108, in <module>
    send(fromaddr, toaddrs, msg)
  File "base.py", line 61, in send
    server.send_message(fromaddr, toaddrs, msg)
  File "/usr/lib/python3.4/smtplib.py", line 829, in send_message
    resent = msg.get_all('Resent-Date')
AttributeError: 'str' object has no attribute 'get_all'
Run Code Online (Sandbox Code Playgroud)

代码(直接链接到麻烦的线)可用在这里.奇怪的是,代码实际上在实际发送任何电子邮件正文之前发送了QUIT - 不确定这是否会影响这一点.

有谁知道导致此错误的原因是什么?

编辑原来我的部分问题是我使用的格式不正确.send_message()需要变量的顺序 …

python email smtplib attributeerror

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

Python类属性错误AttributeError:无法设置属性

class DockerEngine(Device):

  def __init__(self):
      super(DockerInfo, self).__init__()
      self.docker_id = None
      self.host_ip_address = None
      self.total_containers = 0
      self.running_containers = 0
      self.paused_containers = 0
      self.stopped_containers = 0

  @property
  def host_ip_address(self):
      return self._host_ip_address

  @host_ip_address.setter
  def host_it_address(self, ip):
      self._host_ip_address = ip

  @property
  def docker_id(self):
      return self._docker_id

  @docker_id.setter
  def docker_id(self, id):
      self._docker_id = id
Run Code Online (Sandbox Code Playgroud)

当我初始化一个 DockerEngine 对象时,它抱怨 in __init__ self.host_ip_address, can't set attribute。

python setter properties attributeerror python-2.7

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

来自其他文件的烧瓶路由器

我现在正在构建 Flask 应用程序,如下所示。

myserver
- server.py
- myapp
-- urls.py
-- models.py
-- views.py
-- consts.py
Run Code Online (Sandbox Code Playgroud)

我的代码在这里。

服务器.py

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

# Flask App
application = Flask(__name__)

# SQLAlchemy
application.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:./local.db"
db = SQLAlchemy(application)

if __name__ == "__main__":
    application.run(debug=True)
Run Code Online (Sandbox Code Playgroud)

网址.py

from server import application
from . import views

@application.route('/')
def version():
    return views.version()
Run Code Online (Sandbox Code Playgroud)

但是当我运行 server.py 并打开http://localhost:5000/服务器时说404 Not Found

所以我在stackoverflow上搜索,我找到了一些关于Blueprint. 我制作了名为 app 的蓝图app = Blueprint('app', __name__),并从 server.py …

python routes attributeerror flask

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

使用 time.process_time()

我正在尝试计算排序函数需要多长时间,但我正在努力time.process_time()工作。

我目前的设置是:

start = time.process_time()
insertionsort(n)
end = time.process_time()

time = start-end
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我收到此错误:

'float' 对象没有属性 'process_time'

我该如何解决这个问题?我想用time.process_time().

python attributeerror python-3.x

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

如何修复AttributeError:“系列”对象没有属性“ to_numpy”

我的输出:

img

def load_data(self):
    """
    Load data from list of paths
    :return: 3D-array X and 2D-array y
    """
    X = None
    y = None
    df = pd.read_excel('data/Data.xlsx', header=None)
    for i in range(len(df.columns)):
        sentences_ = df[i].to_numpy().tolist()
        label_vec = [0.0 for _ in range(0, self.n_class)]
        label_vec[i] = 1.0
        labels_ = [label_vec for _ in range(0, len(sentences_))]
        if X is None:
            X = sentences_
            y = labels_
        else:
            X += sentences_
            y += labels_
    X, max_length = self.tokenize_sentences(X)
    X = self.word_embed_sentences(X, max_length=self.max_length)
    return np.array(X), …
Run Code Online (Sandbox Code Playgroud)

python attributeerror pandas

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