Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return cursor.fetchone()
@app.delete("/items/{item_id}")
def delete_item(item_id: int):
with CONNECTION.cursor() as cursor:
cursor.execute('DELETE FROM my_table WHERE num=%s RETURNING *;', (item_id, ))
CONNECTION.commit()
return cursor.fetchone()
if __name__ == "__main__":
try:
CONNECTION = psycopg2.connect(dbname='postgres', user='postgres', host='my_db', port=5432)
create_database()
uvicorn.run(app, host="0.0.0.0", port=5000, log_level="info")
finally:
CONNECTION.close()
def run(self, *, host: str, port: int, debug: bool = False) -> None:
self._content = self._render_content()
try:
import uvicorn
uvicorn.run(self.app, host=host, port=port, debug=debug)
except ImportError:
warnings.warn("(!) You need `uvicorn` installed in order to call `run`.")
exit(1)
signature_chain_url: str = cert_chain_url_header) -> JSONResponse:
# It is necessary for correct data validation to serialize data to a JSON formatted string with separators.
request_dict = {
'request_body': json.dumps(data, separators=(',', ':')).encode('utf-8'),
'signature_chain_url': signature_chain_url,
'signature': signature,
'alexa_request': data
}
bot.input_queue.put(request_dict)
loop = asyncio.get_event_loop()
response: dict = await loop.run_in_executor(None, bot.output_queue.get)
response_code = 400 if 'error' in response.keys() else 200
return JSONResponse(response, status_code=response_code)
uvicorn.run(app, host=host, port=port, logger=uvicorn_log, ssl_version=ssl_config.version,
ssl_keyfile=ssl_config.keyfile, ssl_certfile=ssl_config.certfile)
bot.join()
#@app.route("/form")
#def redirect_to_homepage(request):
#@ return RedirectResponse("/")
@app.route('/analyze', methods=['POST'])
async def analyze(request):
data = await request.form()
img_bytes = await (data['file'].read())
img = open_image(BytesIO(img_bytes))
pred_class, pred_idx, outputs = learn.predict(img)[0]
return JSONResponse({'result': str(pred_class)})
if __name__ == '__main__':
uvicorn.run(app, host='0.0.0.0', port=8888)
def run(self, host="0.0.0.0", port=8000):
uvicorn.run(
self.app, host=host, port=port, lifespan="on", access_log=False)
def main():
program = make_program()
make_nodetree(program)
program.pipeline.run()
webserver = WebServer(program)
test_webserver(webserver)
uvicorn.run(webserver.app)
html_file = path / 'view' / 'index.html'
return HTMLResponse(html_file.open().read())
@app.route('/analyze', methods=['POST'])
async def analyze(request):
img_data = await request.form()
img_bytes = await (img_data['file'].read())
img = open_image(BytesIO(img_bytes))
prediction = learn.predict(img)[0]
return JSONResponse({'result': str(prediction)})
if __name__ == '__main__':
if 'serve' in sys.argv:
uvicorn.run(app=app, host='0.0.0.0', port=5000, log_level="info")
}
]
}
]
}
})
for server_id in SERVER_IDS:
create_new_server('fake', IMAGES[0].get('id'), FLAVORS[0].get('id'), server_id)
if __name__ == '__main__':
import uvicorn
LOG.info(f'starting mock openstack server on {PORT}')
uvicorn.run(app, host='0.0.0.0', port=8080, debug=True, log_level=logging.INFO)
loop.close()
@app.route('/')
def index(request):
html = path/'view'/'index.html'
return HTMLResponse(html.open().read())
@app.route('/analyze', methods=['POST'])
async def analyze(request):
data = await request.form()
img_bytes = await (data['file'].read())
img = open_image(BytesIO(img_bytes))
return JSONResponse({'result': learn.predict(img)[0]})
if __name__ == '__main__':
if 'serve' in sys.argv: uvicorn.run(app, host='0.0.0.0', port=8080)
def main():
uvicorn.run(
app,
host='127.0.0.1',
port=9001,
proxy_headers=True,
)