0
저는 pycurl을 사용하여 웹 서버를 설정하고 있습니다. 작은 문제가 있습니다. CURL을 사용하여 명령을 보내면 json 응답이 나옵니다. 그러나 pycurl 메서드를 사용하면 얻을 수 없습니다. 서버에서 응답, 나는 wireshark를 사용하여 패킷 흐름을 확인하고, 패킷은 실제로 서버에 도착하지만 서버가 응답하지 않습니다.웹 서버 pycurl 사용 - GET
클라이언트 측 코드 :
def listUsers(args):
url = 'localhost:7070'
storage = StringIO()
c = pycurl.Curl()
c.setopt(c.URL, url)
c.setopt(c.WRITEFUNCTION, storage.write)
c.perform()
c.close()
content = storage.getvalue()
print content
서버 측 코드 :
def do_GET(self):
print(self.headers)
tmp, user = os.path.split(self.path)
if tmp != '/':
if c.execute('select * from user where username = ?', (user,)).fetchone() is None:
self.send_response(404, 'User %s not found' %user)
self.end_headers()
return
else:
c.execute('select * from user')
recs = c.fetchall()
data = []
for rec in recs:
data.append({"username": rec[0]})
rows_json = json.dumps(data)
self.send_response(200)
self.send_header('content-type', 'application/json')
self.wfile.write(rows_json)
self.end_headers()
self.wfile.close()
print rows_json
return