Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'read' #25

Closed
anusoft opened this issue Apr 1, 2015 · 41 comments
Closed

AttributeError: 'NoneType' object has no attribute 'read' #25

anusoft opened this issue Apr 1, 2015 · 41 comments

Comments

@anusoft
Copy link

anusoft commented Apr 1, 2015

Traceback (most recent call last):
File "echobot.py", line 34, in
for op in client.longPoll():
File "/usr/local/lib/python2.7/dist-packages/line-0.4.1-py2.7.egg/line/client.py", line 504, in longPoll
operations = self._fetchOperations(self.revision, count)
File "/usr/local/lib/python2.7/dist-packages/line-0.4.1-py2.7.egg/line/api.py", line 308, in _fetchOperations
return self._client.fetchOperations(revision, count)
File "/usr/local/lib/python2.7/dist-packages/curve-0.1.0-py2.7.egg/curve/CurveThrift.py", line 483, in fetchOperations
return self.recv_fetchOperations()
File "/usr/local/lib/python2.7/dist-packages/curve-0.1.0-py2.7.egg/curve/CurveThrift.py", line 495, in recv_fetchOperations
(fname, mtype, rseqid) = self._iprot.readMessageBegin()
File "/usr/local/lib/python2.7/dist-packages/thrift-0.9.1-py2.7.egg/thrift/protocol/TCompactProtocol.py", line 308, in readMessageBegin
proto_id = self.__readUByte()
File "/usr/local/lib/python2.7/dist-packages/thrift-0.9.1-py2.7.egg/thrift/protocol/TCompactProtocol.py", line 287, in __readUByte
result, = unpack('!B', self.trans.readAll(1))
File "/usr/local/lib/python2.7/dist-packages/thrift-0.9.1-py2.7.egg/thrift/transport/TTransport.py", line 58, in readAll
chunk = self.read(sz - have)
File "/usr/local/lib/python2.7/dist-packages/thrift-0.9.1-py2.7.egg/thrift/transport/THttpClient.py", line 97, in read
return self.__http.file.read(sz)
AttributeError: 'NoneType' object has no attribute 'read'

Line 34 echobot.py is

while True:
    op_list = []

>>>    for op in client.longPoll():
        op_list.append(op)
@carpedm20
Copy link
Owner

Is this a frequent issue or rare problem?

@anusoft
Copy link
Author

anusoft commented Apr 27, 2015

It rarely happened, only happened for few times

@shinznatkid
Copy link
Contributor

It happen when requests send too much frequency then server will block for a while (3-5 min, sometimes 30 mins, sometimes 2 days)
I found solution is make a persistence connection (I modify Thrift from httplib to requests and make it session as Keep Alive)
I'm not sure the another cause of this problem is thrift URL from "/api/v4/TalkService.do" for Login only or not?
but I've use "/S4" instead (after login and get authToken).

Image of persistence connection

@anusoft
Copy link
Author

anusoft commented Jul 10, 2015

@shinznatkid Thanks for suggestion.

  • I've just added self._headers['Connection'] = "keep-alive" in ready() function
  • Changed command URL to /S4 in ready() function

Will report if there's less ban, thank you again.

@anusoft
Copy link
Author

anusoft commented Jul 13, 2015

@shinznatkid ขอบคุณครับ ใช้งานได้แล้ว สงสัยบอทจะอยู่ใกล้ๆกันนี่ล่ะครับ... :)

@shinznatkid 's solution seem working well, no ban up until now.

This is THttpClient.py that support keep-alive:
(I use patch from this https://issues.apache.org/jira/browse/THRIFT-2033)

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

import httplib
import os
import socket
import sys
import urllib
import urlparse
import warnings
from urllib3 import HTTPConnectionPool, HTTPSConnectionPool
import pprint
import time

from cStringIO import StringIO

from TTransport import *


class THttpClient(TTransportBase):
  """Http implementation of TTransport base."""

  def __init__(self, uri_or_host, port=None, path=None, maxconnections=1):
    """THttpClient supports two different types constructor parameters.

    THttpClient(host, port, path) - deprecated
    THttpClient(uri)

    Only the second supports https.
    """
    if port is not None:
      warnings.warn(
        "Please use the THttpClient('http://host:port/path') syntax",
        DeprecationWarning,
        stacklevel=2)
      self.host = uri_or_host
      self.port = port
      assert path
      self.path = path
      self.scheme = 'http'
    else:
      parsed = urlparse.urlsplit(uri_or_host)
      self.scheme = parsed.scheme
      assert self.scheme in ('http', 'https')
      self.port = parsed.port
      self.host = parsed.hostname
      self.path = parsed.path
      if parsed.query:
        self.path += '?%s' % parsed.query
    self.__wbuf = StringIO()
    self.__custom_headers = {}

    if self.scheme == 'http':
      pool_class = HTTPConnectionPool
    else:
      pool_class = HTTPSConnectionPool
    self.__pool = pool_class(self.host, self.port, maxsize=maxconnections)

  def close(self):
    self.__resp = None

  def isOpen(self):
    return self.__resp is not None

  def setTimeout(self, ms):
    if not hasattr(socket, 'getdefaulttimeout'):
      raise NotImplementedError

    if ms is None:
      self.__pool.timeout = None
    else:
      self.__pool.timeout = ms / 1000.0
  def addHeaders(self, **headers):
    self.__custom_headers.update(headers)

  def setCustomHeaders(self, headers):
    self.__custom_headers = headers

  def read(self, sz):
    return self.__resp.read(sz)

  def write(self, buf):
    self.__wbuf.write(buf)

  def flush(self):

    # Pull data out of buffer
    data = self.__wbuf.getvalue()
    self.__wbuf = StringIO()

    # Prepare headers
    user_agent = 'DESKTOP:MAC:10.10.3-LEOPARD(4.0.3)'
    script = os.path.basename(sys.argv[0])
    if script:
      user_agent = '%s (%s)' % (user_agent, urllib.quote(script))

    headers = {'Host': self.host,
               'Content-Type': 'application/x-thrift',
               'User-Agent': user_agent}
    headers.update(self.__custom_headers)
    # HTTP request
    self.__resp = r = self.__pool.urlopen('POST', self.path, data, headers, preload_content=False)
    # Get reply
    self.code, self.message, self.headers = r.status, r.reason, r.headers
    print time.strftime("%Y-%m-%d %H:%M:%S"), "self.code"
    pprint.pprint(self.code)

@amperespy
Copy link

@anusoft สวัสดีค่ะ เห็นพิมพ์ภาษาไทย พี่คนไทยใช่มั้ยคะ
คือ ติดปัญหาเรื่อง ip ถูกบล็อคค่ะ รบกวนขอคำปรึกษาค่ะ
ขอบคุณมากๆค่ะ

@anusoft
Copy link
Author

anusoft commented Dec 24, 2015

@amperespy โดนบล๊อคเหมือนกันครับ ใช้วิธีตัดต่อเน็ตเอาครับ -_-

@amperespy
Copy link

@anusoft โอเคค่ะ ขอบคุณค่ะะ >*<

@imetanon
Copy link

@anusoft สรุปพี่แก้ปัญหา
File "/usr/local/lib/python2.7/dist-packages/thrift-0.9.1-py2.7.egg/thrift/transport/THttpClient.py", line 97, in read
return self.__http.file.read(sz)
AttributeError: 'NoneType' object has no attribute 'read'
ได้ไหมครับ แล้วใช้วิธีไหน

@zintoo
Copy link

zintoo commented Jan 22, 2016

pip install line -update
มันจะ update thrift
On 22 Jan 2016 10:19, "Metanon J." notifications@github.com wrote:

@anusoft https://github.com/anusoft สรุปพี่แก้ปัญหา
File
"/usr/local/lib/python2.7/dist-packages/thrift-0.9.1-py2.7.egg/thrift/transport/THttpClient.py",
line 97, in read
return self.__http.file.read(sz)
AttributeError: 'NoneType' object has no attribute 'read'
ได้ไหมครับ แล้วใช้วิธีไหน


Reply to this email directly or view it on GitHub
#25 (comment).

@imetanon
Copy link

@zintoo ผมอัพแล้ว แต่มันยังขึ้นแบบนี้
File "/usr/local/lib/python2.7/dist-packages/thrift/transport/THttpClient.py", line 98, in read
return self.__http.file.read(sz)
AttributeError: 'NoneType' object has no attribute 'read'

@zintoo
Copy link

zintoo commented Jan 22, 2016

unistall line แล้วลงใหม่ update pip ให้เป็น version ล่าสุด เพราะ pip
มีปัญหาทำให้ install -update ทำงานไม่ได้
On 22 Jan 2016 11:40, "Metanon J." notifications@github.com wrote:

@zintoo https://github.com/zintoo ผมอัพแล้ว แต่มันยังขึ้นแบบนี้
File
"/usr/local/lib/python2.7/dist-packages/thrift/transport/THttpClient.py",
line 98, in read
return self.__http.file.read(sz)
AttributeError: 'NoneType' object has no attribute 'read'


Reply to this email directly or view it on GitHub
#25 (comment).

@zintoo
Copy link

zintoo commented Jan 22, 2016

https://pip.pypa.io/en/stable/installing/
On 22 Jan 2016 11:47, "zintoo" kzintoo@gmail.com wrote:

unistall line แล้วลงใหม่ update pip ให้เป็น version ล่าสุด เพราะ pip
มีปัญหาทำให้ install -update ทำงานไม่ได้
On 22 Jan 2016 11:40, "Metanon J." notifications@github.com wrote:

@zintoo https://github.com/zintoo ผมอัพแล้ว แต่มันยังขึ้นแบบนี้
File
"/usr/local/lib/python2.7/dist-packages/thrift/transport/THttpClient.py",
line 98, in read
return self.__http.file.read(sz)
AttributeError: 'NoneType' object has no attribute 'read'


Reply to this email directly or view it on GitHub
#25 (comment).

@imetanon
Copy link

@zintoo ตอนนี้ได้ละแต่ผมยังเจอปัญหา ว่า run script นานๆมันยังขึ้น error แบบเดิมครับพอมีวิธีแก้ไหม

@zintoo
Copy link

zintoo commented Jan 24, 2016

ผมไม่เคยเจอ คิดว่าน่าจะเป็นปัญหาที่ เน็ตเวิร์ค ไม่เสถียร
On 24 Jan 2016 13:12, "Metanon J." notifications@github.com wrote:

@zintoo https://github.com/zintoo ตอนนี้ได้ละแต่ผมยังเจอปัญหา ว่า run
script นานๆมันยังขึ้น error แบบเดิมครับพอมีวิธีแก้ไหม


Reply to this email directly or view it on GitHub
#25 (comment).

@imetanon
Copy link

@zintoo ผมพอเจอปัญหาละครับว่ามันมาจาก การ SendMessage ถ้า call ถี่ๆ มันจะทำให้เกิดปัญหา ทำให้โดนแบนชั่วคราวด้วย ไม่แน่ใจพอทราบไหมครับว่าแก้ยังไง

@zintoo
Copy link

zintoo commented Jan 26, 2016

แต่ละ msg delay 15-30 วิ
On 26 Jan 2016 15:43, "Metanon J." notifications@github.com wrote:

@zintoo https://github.com/zintoo ผมพอเจอปัญหาละครับว่ามันมาจาก การ
SendMessage ถ้า call ถี่ๆ มันจะทำให้เกิดปัญหา
ไม่แน่ใจพอทราบไหมครับว่าแก้ยังไง


Reply to this email directly or view it on GitHub
#25 (comment).

@amperespy
Copy link

ตอนนี้จะส่งข้อความ ขึ้นแจ้งว่าให้ใส่ Pin code ใช่มั้ยคะ
มีวิธีแก้ไข ที่ทำให้ไม่ต้องคอยกรอก Pin code มั้ยคะ
ขอบคุณค่ะ

@zier
Copy link

zier commented Feb 2, 2016

@amperespy first time login must verify pin code after you login success you can save certificate and token for next login

@zintoo
Copy link

zintoo commented Feb 2, 2016

เข้าใจว่าเป็นที่ account นั้นมีการใช้งานสมัคร line@ ไว้ด้วย
ทำให้มีการเพิ่มระดับการ verified ซึ่งเหตุผลยังไม่ชัวร์ครับ
account อื่นที่ไม่สมัคร line@ ใช้มาปีกว่าแล้ว มันไม่เห็นเคยขึ้น
On Feb 2, 2016 10:45 AM, "amperespy" notifications@github.com wrote:

ตอนนี้จะส่งข้อความ ขึ้นแจ้งว่าให้ใส่ Pin code ใช่มั้ยคะ
มีวิธีแก้ไข ที่ทำให้ไม่ต้องคอยกรอก Pin code มั้ยคะ
ขอบคุณค่ะ


Reply to this email directly or view it on GitHub
#25 (comment).

@amperespy
Copy link

line@ หมายถึงอย่างไรนะคะ

@zintoo
Copy link

zintoo commented Feb 2, 2016

at.line.me/en/
On Feb 2, 2016 11:48 AM, "amperespy" notifications@github.com wrote:

line@ หมายถึงอย่างไรนะคะ


Reply to this email directly or view it on GitHub
#25 (comment).

@amperespy
Copy link

ไม่ได้สมัครอ่ะค่ะ >*< อาจจะต้องลองแบบ Token ต่อไป ><

@zintoo
Copy link

zintoo commented Feb 2, 2016

ครับ เหตุผลจริง ยังไม่ทราบ ของผม code เดียวกัน ต่าง account อันหนึงขึ้น
อีกอันไม่ขึ้น
On Feb 2, 2016 12:06 PM, "amperespy" notifications@github.com wrote:

ไม่ได้สมัครอ่ะค่ะ >*< อาจจะต้องลองแบบ Token ต่อไป ><


Reply to this email directly or view it on GitHub
#25 (comment).

@amperespy
Copy link

@zier Thank you, but it will be expired, right?

@amperespy
Copy link

รบกวนอีกครั้งค่ะ ใช้ code เดียวกัน
ลอง 3 account สามารถ run ผ่าน เพียง account เดียว
เมื่อเกิด Error แล้ว account นั้น ก็จะไม่สามารถ Login ผ่าน device อื่นๆ ได้ 1 วันค่ะ
แต่เล่นบนมือถือได้ปกติค่ะ

Error ตามนี้ค่ะ พอทราบสาเหตุมั้ยคะ รบกวนด้วยค่ะ ขอบคุณมากค่ะ -/-

client = LineClient(authToken="xxx")
File "/usr/local/lib/python2.7/dist-packages/line-0.8.0-py2.7.egg/line/client.py", line 91, in init
self.revision = self._getLastOpRevision()
File "/usr/local/lib/python2.7/dist-packages/line-0.8.0-py2.7.egg/line/api.py", line 326, in _getLastOpRevision
return self._client.getLastOpRevision()
File "/usr/local/lib/python2.7/dist-packages/curve-0.1.0-py2.7.egg/curve/CurveThrift.py", line 512, in getLastOpRevision
return self.recv_getLastOpRevision()
File "/usr/local/lib/python2.7/dist-packages/curve-0.1.0-py2.7.egg/curve/CurveThrift.py", line 534, in recv_getLastOpRevision
raise result.e
curve.ttypes.TalkException: TalkException(parameterMap=None, reason='REVOKE', code=8)

@zintoo
Copy link

zintoo commented Mar 31, 2016

เป็นเหมือนกันครับ

2016-03-29 11:19 GMT+07:00 amperespy notifications@github.com:

รบกวนอีกครั้งค่ะ ใช้ code เดียวกัน
ลอง 3 account สามารถ run ผ่าน เพียง account เดียว
เมื่อเกิด Error แล้ว account นั้น ก็จะไม่สามารถ Login ผ่าน device อื่นๆ
ได้ 1 วันค่ะ
แต่เล่นบนมือถือได้ปกติค่ะ

Error ตามนี้ค่ะ พอทราบสาเหตุมั้ยคะ รบกวนด้วยค่ะ ขอบคุณมากค่ะ -/-

client = LineClient(authToken="xxx")
File
"/usr/local/lib/python2.7/dist-packages/line-0.8.0-py2.7.egg/line/client.py",
line 91, in init
self.revision = self._getLastOpRevision()
File
"/usr/local/lib/python2.7/dist-packages/line-0.8.0-py2.7.egg/line/api.py",
line 326, in _getLastOpRevision
return self._client.getLastOpRevision()
File
"/usr/local/lib/python2.7/dist-packages/curve-0.1.0-py2.7.egg/curve/CurveThrift.py",
line 512, in getLastOpRevision
return self.recv_getLastOpRevision()
File
"/usr/local/lib/python2.7/dist-packages/curve-0.1.0-py2.7.egg/curve/CurveThrift.py",
line 534, in recv_getLastOpRevision
raise result.e
curve.ttypes.TalkException: TalkException(parameterMap=None,
reason='REVOKE', code=8)


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#25 (comment)

@FrozenFighter
Copy link

@amperespy @zintoo
ได้ล็อกอินไอดีนั้นในคอมหรือป่าวครับ มันล็อกอินบอทกับคอมพร้อมกันไม่ได้นะครับ

ป.ล. ผมใช้อยู่ไม่เจอปัญหาอะไรเลยนะครับ

@amperespy
Copy link

@FrozenFighter

ไม่ได้ Login ในคอมค่ะ

ประเด็นคือ ตอนนี้ทดสอบอยู่ 3 account ค่ะ แต่สามารถ Login โดยใช้ authToken ได้เพียง 1 account
ซึ่ง account ที่สามารถ Login โดยใช้ authToken นั้น เป็น account ที่ใช้มา 4-5 ปีแล้ว

ส่วนอีก 2 account เป็น account ที่เพิ่งทำการสมัคร 3-4 เดือน
โดย 2 account นี้ หาก Login โดยใช้ username/password จะสามารถทำได้ไม่เกิด Error
แต่หาก Login ผ่าน authToken จะเกิด Error ตามที่ได้กล่าวข้างต้นอ่ะค่ะ
จึงยังไม่ทราบสาเหตุว่าเพราะอะไรค่ะ ซึ่งใช้ code เดียวกับ account แรกค่ะ

รบกวนแนะนำด้วยค่ะ ขอบคุณมาก ๆ ค่ะ

@zintoo
Copy link

zintoo commented Apr 1, 2016

เหมือนกันครับ มี หลาย account แต่ตอนนี้ ใช้ได้ 1 account บน windows
แต่ตัวอื่นที่มาลองใน linux โดนแบน 24 ชั่วโมง หลังจาก login

2016-04-01 8:52 GMT+07:00 amperespy notifications@github.com:

@FrozenFighter https://github.com/FrozenFighter

ไม่ได้ Login ในคอมค่ะ

ประเด็นคือ ตอนนี้ทดสอบอยู่ 3 account ค่ะ แต่สามารถ Login โดยใช้ authToken
ได้เพียง 1 account
ซึ่ง account ที่สามารถ Login โดยใช้ authToken นั้น เป็น account ที่ใช้มา
4-5 ปีแล้ว

ส่วนอีก 2 account เป็น account ที่เพิ่งทำการสมัคร 3-4 เดือน
โดย 2 account นี้ หาก Login โดยใช้ username/password จะสามารถทำได้ไม่เกิด
Error
แต่หาก Login ผ่าน authToken จะเกิด Error ตามที่ได้กล่าวข้างต้นอ่ะค่ะ
จึงยังไม่ทราบสาเหตุว่าเพราะอะไรค่ะ ซึ่งใช้ code เดียวกับ account แรกค่ะ

รบกวนแนะนำด้วยค่ะ ขอบคุณมาก ๆ ค่ะ


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#25 (comment)

@FrozenFighter
Copy link

@amperespy เท่าทีผมจำไม่ผิด มันจะเก็บค่าauthToken ไว้ใน directory ที่เรารันบอท คุณลองเปลี่ยนdirectory สำหรับแต่ล่ะ account ดูนะครับ

@zintoo น่าจะปัญหาเดี่ยวกันกับข้างบน สังเกตุจากใช้ได้แค่account เดียว ส่วนเรื่องรันใน linux โดนแบน 24 ชั่วโมง ผมว่าไม่เกี่ยวนะ ผมรันบอทอยู๋ใน VPS debian มาครึ่งปีไม่เคยโดนแบบนะครับ

@amperespy
Copy link

@FrozenFighter

คือ ไม่ได้เก็บไว้ใน Directory อ่ะค่ะ ใช้ code เรียกตรงๆแบบนี้เลยค่ะ
client = LineClient(authToken="xxx")

แต่หากใช้ user/pass สามารถ run ผ่านได้ปกติ ทุก account ค่ะ
client = LineClient( user , password)

ไม่ทราบว่าขอบคุณสามารถ run ผ่าน ได้ทุก account เลยมั้ยค่ะ
แล้วเป็น account ที่ใช้งานมานานยังคะ

ตอนนี้สันนิษฐานเบื้องต้นว่า แต่ละ Account ระดับ verify การใช้งานอาจมีบางอย่าง
ที่แตกต่างกันอยู่ พยายามทดสอบหลายครั้ง ก็ยัง run ไม่ผ่านอ่ะค่ะ

โดย Account ที่ใช้งานได้ สามารถ run ได้ทั้ง Window และ Linux ค่ะ

@FrozenFighter
Copy link

@amperespy ผมมี แค่ไอดีเดียวครับ แล้วสมัครนานแล้ว ผมว่าที่คุณสันนิษฐานคงงถูกแล้งแหละครับ

@zintoo
Copy link

zintoo commented Apr 4, 2016

ผมรันมา ปีกว่า
On Apr 4, 2016 3:20 PM, "FrozenFighter" notifications@github.com wrote:

@amperespy https://github.com/amperespy ผมมี แค่ไอดีเดียวครับ
แล้วสมัครนานแล้ว ผมว่าที่คุณสันนิษฐานคงงถูกแล้งแหละครับ


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#25 (comment)

@amperespy
Copy link

@FrozenFighter @zintoo
ขอบคุณมากค่ะะ ลองต่อไปป >*<

@sodasonic
Copy link

โดน block กันยังครับหรือยังรันกันได้อยู่

@amperespy
Copy link

amperespy commented Nov 1, 2016

@sodasonic
ยังรันใช้งานอยู่ค่ะ แต่ Authen Token ที่สำหรับ Login จะหมดอายุทุก 1 เดือน แล้วต้อง Key pin ที่โทรศัพท์ด้วย
จึงไม่ได้สร้าง File ให้ run auto ค่ะ

ปล. ท่านอื่นมีวิธีสร้าง Token แบบ auto บ้างมั้ยคะะ -/-

@shinomura
Copy link

เพิ่งมาเจอและกำลังลองเทสต์ ไม่ทราบว่าพอจะมีตัวอย่างโค้ดใช้งานจริงให้ดูเป็นตัวอย่างบ้างมั้ยครับ ไม่เคยจับ python เลย ตอนนี้กำลังงมให้มันล็อกอิน ส่งข้อความ ส่งรูปอะไรได้บ้างแล้ว แต่ยังไม่รู้จะไปทางไหนต่อดี = =

@sodasonic
Copy link

sodasonic commented Mar 7, 2017 via email

@sodasonic
Copy link

sodasonic commented Mar 7, 2017 via email

@ii64
Copy link

ii64 commented Jun 22, 2017

Did someone managed THttpClient with PURE TCP, im stuck at reading response with buff size

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests