Reputation: 545
I am using aws sagemaker to invoke the endpoint :
payload = pd.read_csv('payload.csv', header=None)
>> payload
0 1 2 3 4
0 setosa 5.1 3.5 1.4 0.2
1 setosa 5.1 3.5 1.4 0.2
with this code :
response = runtime.invoke_endpoint(EndpointName=r_endpoint,
ContentType='text/csv',
Body=payload)
But I got this problem :
ParamValidationError Traceback (most recent call last)
<ipython-input-304-f79f5cf7e0e0> in <module>()
1 response = runtime.invoke_endpoint(EndpointName=r_endpoint,
2 ContentType='text/csv',
----> 3 Body=payload)
4
5 result = json.loads(response['Body'].read().decode())
~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
312 "%s() only accepts keyword arguments." % py_operation_name)
313 # The "self" in this scope is referring to the BaseClient.
--> 314 return self._make_api_call(operation_name, kwargs)
315
316 _api_call.__name__ = str(py_operation_name)
~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
584 }
585 request_dict = self._convert_to_request_dict(
--> 586 api_params, operation_model, context=request_context)
587
588 handler, event_response = self.meta.events.emit_until_response(
~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _convert_to_request_dict(self, api_params, operation_model, context)
619 api_params, operation_model, context)
620 request_dict = self._serializer.serialize_to_request(
--> 621 api_params, operation_model)
622 prepare_request_dict(request_dict, endpoint_url=self._endpoint.host,
623 user_agent=self._client_config.user_agent,
~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/validate.py in serialize_to_request(self, parameters, operation_model)
289 operation_model.input_shape)
290 if report.has_errors():
--> 291 raise ParamValidationError(report=report.generate_report())
292 return self._serializer.serialize_to_request(parameters,
293 operation_model)
ParamValidationError: Parameter validation failed:
Invalid type for parameter Body, value: 0 1 2 3 4
0 setosa 5.1 3.5 1.4 0.2
1 setosa 5.1 3.5 1.4 0.2, type: <class 'pandas.core.frame.DataFrame'>, valid types: <class 'bytes'>, <class 'bytearray'>, file-like object
I am just using the same code/step like in the aws tutorial .
Can you help me to resolve this problem please?
thank you
Upvotes: 4
Views: 6490
Reputation: 5568
The payload variable is a Pandas' DataFrame, while invoke_endpoint() expects Body=b'bytes'|file
.
Try something like this (coding blind):
response = runtime.invoke_endpoint(EndpointName=r_endpoint,
ContentType='text/csv',
Body=open('payload.csv'))
More on the expected formats here. Make sure the file doesn't include a header.
Alternatively, convert your DataFrame to bytes, like in this example, and pass those bytes instead of passing a DataFrame.
Upvotes: 5