コード例 #1
0
ファイル: handler.py プロジェクト: Reneee/Backend
	def do_GET(self):
		try:
			parsed = url_parser.parse(self.path)
		except:
			self.send_error(404)
			return
		
		try:
			r = db.query(parsed)
		except:
			self.send_error(500)
			return

		self.send_response(200)
		self.send_header("Content-type", "application/json;charset=utf-8")

		self.send_header("Content-length", len(r))
		self.end_headers()
		self.wfile.write(r.encode("utf-8"))
		self.wfile.flush()
コード例 #2
0
ファイル: handler.py プロジェクト: seadsystem/api
	def do_GET(self):
		try:
			parsed = url_parser.parse(self.path)
		except Exception as inst:
			if self.path == '/':
				self.send_response(200)
				self.send_header("Content-type", "text/plain")
				self.end_headers()
				self.wfile.write(USAGE.encode("utf-8"))
				self.wfile.flush()
			else:
				print(type(inst))
				print(inst.args)
				print(inst)

				self.send_error(404)
			return

		try:
			r = db.query(parsed)

			self.send_response(200)
			self.send_header("Content-type", "application/json;charset=utf-8")  # Not actually using JSON format. Causes errors in Chrome when it tries to validate

			self.end_headers()
			for line in r:
				self.wfile.write(line.encode("utf-8"))
		except Exception as inst:
			self.send_error(500)
			print(type(inst))
			print(inst.args)
			print(inst)

			return

		self.wfile.flush()
コード例 #3
0
ファイル: views.py プロジェクト: vishalsodani/50Apps-Week3
def result(request):
    url = request.POST["url_input"]
    result = parse(url)
    return render_to_response("result.html", {"result": result}, context_instance=RequestContext(request))