SerenityS / kakaobot_hyoammeal

효암고등학교 카카오톡 플러스친구 급식봇입니다.
MIT License
10 stars 6 forks source link

자꾸만 오류가 출력됩니다. 제발 도와주세요 #3

Closed rackis closed 6 years ago

rackis commented 6 years ago

개발 환경은 Amazon Web Service를 이용하려다 해외결제 가능한 카드가 없어 라즈베리 파이를 구매하여 라즈비안 운영체제를 설치하여 구성하였습니다.

  1. 기초 패키지 설치에서 sudo apt-get update sudo apt-get upgrade sudo apt-get install python3 python3-pip python3-venv 진행 성공하였고,

  2. 레포지터리 클론 및 이동에서 git clone https://github.com/SerenityS/kakaobot_hyoammeal /home/pi/Desktop/KAKAO cd /home/pi/Desktop/KAKAO 하였고요

  3. python 가상환경 구축 및 실행에서 python3 -m venv myvenv source myvenv/bin/activate 해서 가상환경에서 진행 시작하였습니다.

  4. python 추가 요구 패키지 설치에서 pip install Django lxml beautifulsoup4 python-dateutil 입력하니 lxml설치하다 오류가 발생하여 pip install Django beautifulsoup4 python-dateutil sudo apt-get install python-lxml sudo apt-get install libxml2-dev libxslt-dev python-dev 로 대체하여 설치했습니다. 여기서 문제가 있는지도 모르겠습니다.

  5. 첫 마이그레이션 & 실행에서 python3 manage.py migrate 마이그레이트는 성공했고 python3 manage.py runserver 2**.*..31:8000 하여

Performing system checks...

System check identified no issues (0 silenced). November 16, 2017 - 13:55:23 Django version 1.11.7, using settings 'kakaobot.settings' Starting development server at http://2**.***.**.31:8000/ Quit the server with CONTROL-C. 라고 뜨는 거로 봐서는 서버 구동은 성공한 것 같습니다.

  1. 동작 확인에서 브라우저에서 http://2**.***.**.31:8000/keyboard/ 들어가보면 {"type": "buttons", "buttons": ["\uc870\uc2dd", "\uc911\uc2dd", "\uc11d\uc2dd", "\ub0b4\uc77c\uc758 \uc870\uc2dd", "\ub0b4\uc77c\uc758 \uc911\uc2dd", "\ub0b4\uc77c\uc758 \uc11d\uc2dd"]} 정상적으로 나오기에 괜찮을거라 생각했습니다. 터미널에서 명령어 치니까 엔터친 상태로 가만히 있더라고요 반응이 느린건지...

  2. 학교 코드 수정에서는 hyoammeal/views.py를 열어보라고 했는데 업데이트이후 경로가 crawl.py로 바뀐 것 같아 그곳을 수정했습니다.

  3. crontab을 통한 crawl.py의 주기적 실행에서는 어떠한 것을 실행해야 하는지 모르겠어서 아무것도 행하지 않았습니다.

  4. 카카오톡 플러스 친구와 연동에서 주소 : https://center-pf.kakao.com/_KaLxlxl 이름 : 경상고 자율동아리 나비효과

스마트 채팅 등록에서 API형 선택하여 앱 URL http://2**.***.**.31:8000로 API 테스트를 진행하니 Required* keyboard OK {"type":"buttons","buttons":["아침","점심","저녁","내일 아침","내일 점심","내일 저녁"]} 라는 결과가 나왔고요, 휴대폰으로 들어가 확인해보니 버튼들이 정상적으로 출력되었습니다. 그러나 버튼을 누르면 [관리자에게만 발송되는 메시지입니다] 사용자 봇서버에 에러가 감지 되었습니다. 내용:[잘못된 응답입니다. response is not OK(200) : 500 / Internal Server Error] 해당 프로필의 자동응답 시스템이 응답을 하지 않습니다. 문제가 보고되어 처리 예정입니다. 다음에 다시 시도해주세요.

라고 오류가 출력 되었습니다.

계속된 오류 출력으로 인해 공유기 포트포워딩을 다시 해보기도 하고 공유기를 제거해보기도 하고 윈도우에 설치하여 진행해보기도 하고 진짜 여러 번을 몇 달 동안 해보고 있습니다. 다른 사례들을 참고 해서 수정하려 해봐도 어떤 부분에서 정확히 어떤 오류인지를 알 수가 없어 혼란스럽고 짜증나기만 합니다. 제가 능력이 너무나도 부족하여 어떻게 하여야 할지 방향을 잡을 수가 없어서 질문합니다. 혹시 시간되신다면 최대한 빠른 시간 내에 도와주시면 좋겠습니다. 이번 주 주말까지만 시도해보고 안되면 포기하려고 합니다. 읽어주셔서 감사합니다.

SerenityS commented 6 years ago

crawl.py 실행해서 급식 정보가 담긴 txt 만들어줘야합니다.

SerenityS commented 6 years ago

KAKAO폴더에서 python3 hyoammeal/crawl.py 로 실행시켜주세요

rackis commented 6 years ago

실행 시켜보려 시도하니 Traceback (most recent call last): File "hyoammeal/crawl.py", line 19, in soup = BeautifulSoup(source, "lxml", from_encoding='utf-8') File "/home/pi/Desktop/KAKAO/myvenv/lib/python3.5/site-packages/bs4/init.py", line 165, in init % ",".join(features)) bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library? 라고 뜨네요. lxml이 좀 이상한가 봅니다. 분명 pip install 하니까 오류가 나서 sudo apt-get install python-lxml sudo apt-get install libxml2-dev libxslt-dev python-dev로 대체하여 설치 하였는데 이상합니다. pip install lxml==3.6.0 이 명령어로 다시 한번 설치 중입니다.

Collecting lxml==3.6.0 Downloading lxml-3.6.0.tar.gz (3.7MB) 100% |████████████████████████████████| 3.7MB 78kB/s Building wheels for collected packages: lxml Running setup.py bdist_wheel for lxml ... error Complete output from command /home/pi/Desktop/KAKAO/myvenv/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-go0qwn9s/lxml/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/tmpbd5n8v8wpip-wheel- --python-tag cp35: Building lxml version 3.6.0. Building without Cython. Using build configuration of libxslt 1.1.29 usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: -c --help [cmd1 cmd2 ...] or: -c --help-commands or: -c cmd --help

error: invalid command 'bdist_wheel'


Failed building wheel for lxml 그러나 빨간색으로 빌드 실패했다 뜨고 Running setup.py clean for lxml Failed to build lxml Installing collected packages: lxml Running setup.py install for lxml ...

설치가 진행이 되지 않네요 lxml 설치 방법이 따로 있나요? 아니면 설치 되어있는데 제가 오류의 요점을 파악하지 못하고 있는건가요?

SerenityS commented 6 years ago

그냥 pip로 깔면 되지 않나요? pip install lxml

rackis commented 6 years ago

죄송합니다. 좀 많이 늦었습니다. 라즈베리파이를 초기화 하고 재설치 진행하였습니다. 그러나 또다시 pip install lxml은 오류를 뿜으면서 설치 진행이 안되네요 Collecting lxml Downloading lxml-4.1.1.tar.gz (2.4MB) 100% |████████████████████████████████| 2.4MB 118kB/s Building wheels for collected packages: lxml Running setup.py bdist_wheel for lxml ... error Complete output from command /home/pi/Desktop/KAKAO/myvenv/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-0xxbgmb3/lxml/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/tmpjmxm3dxzpip-wheel- --python-tag cp35: Building lxml version 4.1.1. Building without Cython. ERROR: b'/bin/sh: 1: xslt-config: not found\n' make sure the development packages of libxml2 and libxslt are installed

Using build configuration of libxslt usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: -c --help [cmd1 cmd2 ...] or: -c --help-commands or: -c cmd --help

error: invalid command 'bdist_wheel'


Failed building wheel for lxml Running setup.py clean for lxml Failed to build lxml Installing collected packages: lxml Running setup.py install for lxml ... error Complete output from command /home/pi/Desktop/KAKAO/myvenv/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-0xxbgmb3/lxml/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-h4wb_f3f-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/Desktop/KAKAO/myvenv/include/site/python3.5/lxml: Building lxml version 4.1.1. Building without Cython. ERROR: b'/bin/sh: 1: xslt-config: not found\n' make sure the development packages of libxml2 and libxslt are installed

Using build configuration of libxslt
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-3.5
creating build/lib.linux-armv7l-3.5/lxml
copying src/lxml/doctestcompare.py -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/_elementpath.py -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/cssselect.py -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/__init__.py -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/builder.py -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/usedoctest.py -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/pyclasslookup.py -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/sax.py -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/ElementInclude.py -> build/lib.linux-armv7l-3.5/lxml
creating build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/__init__.py -> build/lib.linux-armv7l-3.5/lxml/includes
creating build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/diff.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/__init__.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/soupparser.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/formfill.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/_html5builder.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/_setmixin.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/_diffcommand.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/builder.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/usedoctest.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/html5parser.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/clean.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/defs.py -> build/lib.linux-armv7l-3.5/lxml/html
copying src/lxml/html/ElementSoup.py -> build/lib.linux-armv7l-3.5/lxml/html
creating build/lib.linux-armv7l-3.5/lxml/isoschematron
copying src/lxml/isoschematron/__init__.py -> build/lib.linux-armv7l-3.5/lxml/isoschematron
copying src/lxml/etree.h -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/etree_api.h -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/lxml.etree.h -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/lxml.etree_api.h -> build/lib.linux-armv7l-3.5/lxml
copying src/lxml/includes/relaxng.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/xslt.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/__init__.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/dtdvalid.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/config.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/tree.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/xmlparser.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/xmlschema.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/c14n.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/xinclude.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/etreepublic.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/xpath.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/htmlparser.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/uri.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/schematron.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/xmlerror.pxd -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/etree_defs.h -> build/lib.linux-armv7l-3.5/lxml/includes
copying src/lxml/includes/lxml-version.h -> build/lib.linux-armv7l-3.5/lxml/includes
creating build/lib.linux-armv7l-3.5/lxml/isoschematron/resources
creating build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/rng
copying src/lxml/isoschematron/resources/rng/iso-schematron.rng -> build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/rng
creating build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl
copying src/lxml/isoschematron/resources/xsl/XSD2Schtrn.xsl -> build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl
copying src/lxml/isoschematron/resources/xsl/RNG2Schtrn.xsl -> build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl
creating build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl -> build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl -> build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_abstract_expand.xsl -> build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_schematron_message.xsl -> build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/iso_dsdl_include.xsl -> build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
copying src/lxml/isoschematron/resources/xsl/iso-schematron-xslt1/readme.txt -> build/lib.linux-armv7l-3.5/lxml/isoschematron/resources/xsl/iso-schematron-xslt1
running build_ext
building 'lxml.etree' extension
creating build/temp.linux-armv7l-3.5
creating build/temp.linux-armv7l-3.5/src
creating build/temp.linux-armv7l-3.5/src/lxml
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-RUbMX3/python3.5-3.5.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DCYTHON_CLINE_IN_TRACEBACK=1 -Isrc -Isrc/lxml/includes -I/home/pi/Desktop/KAKAO/myvenv/include -I/usr/include/python3.5m -c src/lxml/etree.c -o build/temp.linux-armv7l-3.5/src/lxml/etree.o -w
In file included from src/lxml/etree.c:619:0:
src/lxml/includes/etree_defs.h:14:31: fatal error: libxml/xmlversion.h: 그런 파일이나 디렉터리가 없습니다
 #include "libxml/xmlversion.h"
                               ^
compilation terminated.
Compile failed: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
creating tmp
cc -I/usr/include/libxml2 -c /tmp/xmlXPathInitjl7rq4ed.c -o tmp/xmlXPathInitjl7rq4ed.o
/tmp/xmlXPathInitjl7rq4ed.c:1:26: fatal error: libxml/xpath.h: 그런 파일이나 디렉터리가 없습니다
 #include "libxml/xpath.h"
                          ^
compilation terminated.
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1

----------------------------------------

Command "/home/pi/Desktop/KAKAO/myvenv/bin/python3 -u -c "import setuptools, tokenize;file='/tmp/pip-build-0xxbgmb3/lxml/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-h4wb_f3f-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/Desktop/KAKAO/myvenv/include/site/python3.5/lxml" failed with error code 1 in /tmp/pip-build-0xxbgmb3/lxml/

rackis commented 6 years ago

오류 해결법을 찾아보면 https://gist.github.com/bluesid/6828e2d51f1a3f3bbb76c8944e1a57b9 sudo apt-get install python-lxml sudo apt-get install libxml2-dev libxslt-dev python-dev 이것으로 대체해도 된다고 하는데 이대로 해도 될지 확신이 없습니다.

SerenityS commented 6 years ago

sudo apt install xslt-config

애초에 pip로 걸어도 빌드하는게 아닌데 이상하네요;

rackis commented 6 years ago

sudo apt install xslt-config 이거는 무엇을 하는건가요? 입력하면 패키지 목록을 읽는 중입니다... 완료 의존성 트리를 만드는 중입니다
상태 정보를 읽는 중입니다... 완료 E: xslt-config 패키지를 찾을 수 없습니다

이렇게 되면서 설치가 안되네요...

rackis commented 6 years ago

오!! http://lxml.de/installation.html에서 본 대로 CFLAGS="-O0" pip install lxml 로 설치를 진행하니 설치가 완료되고 python3 hyoammeal/crawl.py 실행하여 카카오톡 api에서 작동 잘 되는것을 확인했습니다. 도와주셔서 정말 감사합니다. 아무래도 명령어를 다른거로 사용하면서 python3가 lxml을 인식하지 못하였던것 같습니다. 시간 내주셔서 정말 고맙습니다. 마지막으로 crontab을 통한 crawl.py의 주기적 실행이라는것이 설명에는 crontab -e

매주 일요일 0시 0분에 crawl.py 실행

0 0 7 cd ~/meal && /usr/bin/python3 ~/meal/hyoammeal/crawl.py 라고만 되있는데 저 3줄을 다 복사해서 쉘에 넣었더니

GNU nano 2.7.4 File:/tmp/crontab.6pihtI/crontab modified

매주 일요일 0시 0분에 crawl.py 실행

0 0 7 cd ~/meal && /usr/bin/python3 ~/meal/hyoammeal/crawl.py .......... 중략 이런게 적힌 창으로 쉘이 바뀝니다. 그러면 된건가요? 그리고 그 창은 꺼도 되는건가요?

SerenityS commented 6 years ago

경로는 다시 맞춰주셔야합니다 crontab -e 입력하시면 입력창뜰튼데 그 맨밑에 두줄 넣으시면 됩니다

rackis commented 6 years ago

매주 일요일 0시 0분에 crawl.py 실행

0 0 7 cd /home/pi/Desktop/KAKAO && /usr/bin/python3 /home/pi/Desktop/KAKAO/hyoammeal/crawl.py 로 하면 되겠지요. 도와주셔서 정말 감사합니다. 그리고 소스 만들어주셔서도요. 덕분에 몇달간 머리아프던게 해결되었습니다. 고맙습니다.^^

SerenityS commented 6 years ago

파이썬 주소도 가상환경에 맞춰줘야할것같네요. 수고하셨습니다 ㅎ