hug

How to send a pandas dataframe using POST method and receive it in Hug/other REST API framework? pickle.loads fails to unpickle after sending

让人想犯罪 __ 提交于 2020-02-02 13:13:51
问题 How to send a pandas DataFrame using a POST method? For example, the following hug server listens to a POST requests and responds with a pickled pandas DataFrame: import hug import pickle import traceback import pandas as pd @hug.post() def call(pickle_dump): print(type(pickle_dump)) try: df = pickle.loads(pickle_dump) return pickle.dumps(df.iloc[0]) except: print(traceback.format_exc()) return pickle.dumps(pd.DataFrame()) When the following POST request is made: import requests import pandas

How to send a pandas dataframe using POST method and receive it in Hug/other REST API framework? pickle.loads fails to unpickle after sending

半腔热情 提交于 2020-02-02 13:13:08
问题 How to send a pandas DataFrame using a POST method? For example, the following hug server listens to a POST requests and responds with a pickled pandas DataFrame: import hug import pickle import traceback import pandas as pd @hug.post() def call(pickle_dump): print(type(pickle_dump)) try: df = pickle.loads(pickle_dump) return pickle.dumps(df.iloc[0]) except: print(traceback.format_exc()) return pickle.dumps(pd.DataFrame()) When the following POST request is made: import requests import pandas

Passing parameters in hug server as /foo/something in double number function

ぃ、小莉子 提交于 2020-01-16 12:02:07
问题 I want to get the double of one number when I access to URL /double/<number> in hug server. Something like routing in flask. Is it possible to do that? In documentation of hug server, I did not found nothing: My code would seem like: @hug.get('/double', number) def doubles(n): return 2*n 回答1: Yup, you can do: import hug @hug.get("/double/{number}") def doubles(response, number: hug.types.number): return 2 * number Note, that if you don't define type it will default to string . 来源: https:/

How to send a pandas dataframe using POST method and receive it in Hug/other REST API framework? pickle.loads fails to unpickle after sending

感情迁移 提交于 2019-12-07 17:14:17
How to send a pandas DataFrame using a POST method? For example, the following hug server listens to a POST requests and responds with a pickled pandas DataFrame: import hug import pickle import traceback import pandas as pd @hug.post() def call(pickle_dump): print(type(pickle_dump)) try: df = pickle.loads(pickle_dump) return pickle.dumps(df.iloc[0]) except: print(traceback.format_exc()) return pickle.dumps(pd.DataFrame()) When the following POST request is made: import requests import pandas as pd df = pd.DataFrame(pd.np.random.randn(10,20)) r = requests.post('http://localhost:8000/call',