I'm trying to post an XML to my API and although it works fine from the URL if I try to CURL the XML file in I get an "Invalid drive specification" error.
This is my CURL command -
curl -X POST -d 5022_4qa.xml http://servername:9001/deploy/calendar/&format=xml
As soon as I try the curl I get back a few errors before it fails. My assumption is that it's not grabbing the XML file for some reason. I can even put the full path of the file the error is the same.
....
</div>{
"evntmst_type": [
"This field is required."
],
"evntmst_id": [
"This field is required."
],
"evntmst_name": [
"This field is required."
]
}</pre>
....
Invalid drive specification
In the return on the API side it's returning a 400 code.
To post the contents of a file with curl, you need to prefix the file name with #. So:
curl -X POST -d #5022_4qa.xml http...
Related
I've deployed a tensorflow multi-label classification model using a sagemaker endpoint as follows:
predictor = sagemaker_model.deploy(initial_instance_count=1, instance_type="ml.m5.2xlarge", endpoint_name='testing-2')
It gets deployed and works fine when I invoke it from the Sagemaker Jupyter instance:
sample = ['this movie was extremely good']
output=predictor.predict(sample)
output:
{'predictions': [[0.00370046496,
4.32942124e-06,
0.00080883503,
9.25126587e-05,
0.00023958087,
0.000130862]]}
However, I am unable to send a request to the deployed endpoint from other notebooks or sagemaker studio. I'm unsure of the request format.
I've tried several variations in the input format and still failed. The error message is as below:
sagemaker error
Request:
{
"body": {
"text": "Testing model's prediction on this text"
},
"contentType": "application/json",
"endpointName": "testing-2",
"customURL": "",
"customHeaders": [
{
"Key": "sm_endpoint_name",
"Value": "testing-2"
}
]
}
Error:
Error invoking endpoint: Received client error (400) from primary with message "{ "error": "Failed to process element:
0 key: text of 'instances' list. Error: INVALID_ARGUMENT: JSON object: does not have named input: text" }".
See https://us-west-2.console.aws.amazon.com/cloudwatch/home?region=us-west-2#logEventViewer:group=/aws/sagemaker/Endpoints/testing-2
in account 793433463428 for more information.
Is there any way to find out exactly how the model expects the request format to be?
Earlier I had the same model on my local system and the way I tested it was using this curl request:
curl -s -H 'Content-Type: application/json' -d '{"text": "what ugly posts"}' http://localhost:7070/sentiment
And it worked fine without any issues.
I've tried different formats and replaced the "text" key inside body with other words like "input", "body", nothing etc.
Based on your description above, I assume you are deploying the TensorFlow model using the SageMaker TensorFlow container.
If you want to view what your model expects as input you can use the saved_model CLI:
1
├── keras_metadata.pb
├── saved_model.pb
└── variables
├── variables.data-00000-of-00001
└── variables.index
!saved_model_cli show --all --dir {"1"}
After you have confirmed the input name above you can invoke the endpoint as follows:
import json
import boto3
client = boto3.client('runtime.sagemaker')
data = {"instances": ['this movie was extremely good']}
response = client.invoke_endpoint(EndpointName=<EndpointName>,
Body=json.dumps(data))
response_body = response['Body']
print(response_body.read())
The same payload can then also be used in Studio when invoking the endpoint.
I'm trying to use Google's translate method from its Translation API as documented here, but for some reason the translations I get replace non-Latin characters with underscores.
For instance, with curl on the command-line:
$ curl -X POST 'https://translation.googleapis.com/language/translate/v2/?source=en&target=de&q=Practicing+diligently+each+day+means+inevitable+improvement.&key=MY_API_KEY'
{
"data": {
"translations": [
{
"translatedText": "T_glich flei_ig zu _ben, bedeutet unausweichliche Verbesserung."
}
]
}
}
Compare to the English-to-German result from translate.google.com:
Täglich fleißig zu üben, bedeutet unausweichliche Verbesserung.
It's especially bad when the target is a language like Japanese, which doesn't contain Latin characters:
$ curl -X POST 'https://translation.googleapis.com/language/translate/v2/?source=en&target=ja&q=Practicing+diligently+each+day+means+inevitable+improvement.&key=MY_API_KEY'
{
"data": {
"translations": [
{
"translatedText": "______________________________________________________"
}
]
}
}
Maybe this is a trial account limitation? Nothing I've seen in this docs would indicate this, however.
I believe it's a string-encoding issue.
I assume your HTTP request body is being sent using application/x-www-form-urlencoded - which does not support characters above 0x7F (128) as literal text, see here: application/x-www-form-urlencoded and charset="utf-8"?
I suggest:
POST with an explicit Content-Type: application/json header with the charset=utf-8 field set. (x-www-form-urlencoded does not support the charset field).
Ensure your terminal is using UTF-8
Also take a look using a tool like Wireshark, or create the request in JavaScript using fetch and use Chrome's Developer Tools' Network tab's "Copy as cURL (Bash)" command to get the terminal command to use.
Somewhat embarrassingly, this was actually just an issue with tmux, the terminal multiplexer I was using to read the output of every call I made to the Translation API, both with curl and with the printed output of the code I was writing.
As per this Ask Ubuntu answer to someone else's tmux question, this is fixable by explicitly telling tmux to launch with UTF-8 support, i.e., tmux -u.
Thanks both to Dai and Daniel for pointing to a potential terminal issue.
I just tried with the following request and it worked well:
curl -X POST "https://translation.googleapis.com/language/translate/v2?key=MY_API_KEY" \
-H "Content-Type: application/json" \
--data "{
'q': 'Practicing diligently each day means inevitable improvement.',
'source': 'en',
'target': 'de'
}"
Giving this output:
{
"data": {
"translations": [
{
"translatedText": "Täglich fleißig zu üben, bedeutet unausweichliche Verbesserung."
}
]
}
}
And for the Japanese output:
{
"data": {
"translations": [
{
"translatedText": "毎日熱心に練習することは避けられない改善を意味します。"
}
]
}
}
Hope it helps
I am trying to send a request to aws elasticsearch with aws-es-curl:
aws-es-curl https://myhost.es.amazonaws.com/my-index/_search?pretty -H 'Content-Type: application/json' -d'{"query":{"match_all":{}},"size": "100","index":"my-index", "_source": {"excludes": ["attachment.*","data"], "includes": "owner"}}'
But this returns me all fields. Also I size parameter is also not recognized :( Why this happens? How pass those parameters to es?
ES version is 5.3
Source variants are here
Try to pipe the content of your query into the curl command:
echo '{"query":{"match_all":{}},"size": "100", "_source": {"excludes": ["attachment.*","data"], "includes": "owner"}}' | aws-es-curl -X POST https://myhost.es.amazonaws.com/my-index/_search
I am trying to follow the example on google speech api found here
https://cloud.google.com/speech/docs/getting-started
1) I created the follow json request file
{
'config': {
'encoding':'FLAC',
'sampleRate': 16000,
'languageCode': 'en-US'
},
'audio': {
'uri':'gs://cloud-samples-tests/speech/brooklyn.flac'
}
}
2) Authenticate to my service account
gcloud auth activate-service-account --key-file=service-account-key-file
3) Obtain my authorization token successfully
gcloud auth print-access-token
access_token
4) Then use the following curl command
curl -s -k -H "Content-Type: application/json" \
-H "Authorization: Bearer access_token" \
https://speech.googleapis.com/v1beta1/speech:syncrecognize \
-d #sync-request.json
But I keep getting the following response
{
"error": {
"code": 400,
"message": "Invalid recognition 'config': bad encoding..",
"status": "INVALID_ARGUMENT"
}
}
Do I need access permissions for the uri gs://cloud-samples-tests/speech/brooklyn.flac? Is that what the problem is?
Thanks in advance..
In my opinion, it is a file format issue.
You have to send WAV file instead of FLAC ...
[ FLAC and MP3 format are not supported <=> need a file conversion (representing cost) on the server side ]
Convert your audio file to WAV (using ffmpeg or avconv), then retry.
You may also take a look here (to see a working example)
For me, the solution was to remove the space between "-d #",
so change "-d #sync-request.json" to "-d#sync-request.json".
I got help here: https://groups.google.com/forum/#!topic/cloud-speech-discuss/bL_N5aJDG5A. Apparently the file was being read and processed, but the parms were going to the "curl.exe" instead of being passed to the URL.
I understand this is quite late for an answer. However, it might help others so putting in your error.
The config that you are passing is actually incorrect. The attributes should be like:
{
"config": {
"encoding": "LINEAR16",
"sampleRateHertz": 16000,
"languageCode": "en-US",
"maxAlternatives": 1,
"profanityFilter": true,
"enableWordTimeOffsets": false
},
"uri": {
"content":"<your uri>"
}
}
I can install it with URL, but i can't upload to firefox marketplace.
but i have 2 errors:
JSON Parse Error
Error: The webapp extension could not be parsed due to a syntax error in the JSON.
No JSON object could be decoded: line 1 column 0 (char 0)
well the json is this:
{
"name": "Snake",
"description": "Snake in html and js",
"launch_path": "/index.html",
"developer": {
"name": "ZiTAL",
"url": "https://github.com/ZiTAL/snakejs"
},
"icons": {
"128": "/img/snake-128.png"
},
"installs_allowed_from": ["*"]
}
Second error:
Manifests must be served with the HTTP header "Content-Type: application/x-web-app-manifest+json". See https://developer.mozilla.org/docs/Web/Apps/Manifest#Serving_manifests for more information.
well if i downloaded with wget:
wget http://myurl/manifest.webapp
the header is OK
HTTP eskaera bidalia, erantzunaren zain... 200 OK
Luzera: 267 [application/x-web-app-manifest+json]
Saving to: ‘manifest.webapp’
To validate the app, you need to put the manifest.webapp url, not the app url:
http://myurl/manifest.webapp
Second error:
You could try wget --save-headers and look in the output file, if the Content-Type header is really correct...