프로젝트가 진행 중입니다. 프로젝트 폴더에는 다른 폴더 (lib)가 있고이 폴더에는 2 개의 파일이 있습니다. 각각의 내용은 다음과 같습니다. 문제는 req.py가 완벽하게 실행된다는 것입니다.하지만 main.py를 실행하면 다음 오류가 발생합니다. 아래main에서 호출 된 경우 Python 모듈이 작동하지 않습니까?
Traceback (most recent call last):
File "C:\Users\redacted\main.py", line 5, in <module>
req.req()
File "C:\Users\redacted\lib\req.py", line 13, in req
return r.content
File "C:\Python27\lib\site-packages\requests\models.py", line 595, in content
content = decode_gzip(self._content)
File "C:\Python27\lib\site-packages\requests\utils.py", line 354, in decode_gzip
return zlib.decompress(content, 16 + zlib.MAX_WBITS)
TypeError: must be string or read-only buffer, not None
설정 :
__init__.py:import req
main.py
import lib as n
if __name__ == "__main__":
req = n.req.req()
req.req()
req.py
import requests
class req():
def __init__(self):
ua = 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2'
self.w = requests.session(headers = { 'User-Agent': ua })
def req(self):
r = self.w.get('http://www.google.com')
return r.content
if __name__ == "__main__":
r = req()
print r.req()
내가 아이디어에서 완전히입니다. 이 문제의 원인에 대한 설명이 있습니까?
마지막 줄뿐만 아니라 모든 추적 표시. –
요청 모듈이란 무엇이며 어디에서 찾을 수 있습니까? – JeremyFromEarth
전체 추적을 추가했습니다. 요청 : http://docs.python-requests.org/ko/latest/index.html –