Posts: 5
Threads: 2
Joined: Jan 2019
Jan-13-2019, 09:16 AM
(This post was last modified: Jan-13-2019, 06:00 PM by Larz60+.)
I try to add Vietnamese accent by using API on this : link((on API: Add Accents) but bad request(400).
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import requests
headers = {
'api_key' : "5268c1bfd9da46c996d50649b23b59f5" ,
'Cache-Control' : "no-cache"
}
response = requests.request( "-X GET" ,url,headers = headers)
print (response.text)
|
I'm a beginner to this.
Posts: 12,025
Threads: 484
Joined: Sep 2016
Jan-13-2019, 06:01 PM
(This post was last modified: Jan-13-2019, 06:02 PM by Larz60+.)
400 error is:
Quote:6.5.1. 400 Bad Request
The 400 (Bad Request) status code indicates that the server cannot or
will not process the request due to something that is perceived to be
a client error (e.g., malformed request syntax, invalid request
message framing, or deceptive request routing).
It probably doesn't like the format of your header or the URL is incorrect
Posts: 95
Threads: 1
Joined: Apr 2018
Jan-13-2019, 06:19 PM
(This post was last modified: Jan-13-2019, 06:20 PM by mlieqo.)
Hey manhsv,
if you look at the doc page for this 'add' service you can see it also has some required query parameters, in this case 'text'. So you need to also send this 'text' parameter as part of your request.
Also your request type is currently '-X GET' and '-X' is actually just a parameter specifying request method for the curl command so you can skip that and just go with GET or just simply using method requests.get() .
1 2 |
payload = { 'text' : 'some text here' }
response = requests.get(url, headers = headers, data = payload)
|
Posts: 5
Threads: 2
Joined: Jan 2019
Jan-14-2019, 07:25 AM
(This post was last modified: Jan-14-2019, 07:25 AM by manhsv.)
(Jan-13-2019, 06:19 PM)mlieqo Wrote: Hey manhsv,
if you look at the doc page for this 'add' service you can see it also has some required query parameters, in this case 'text'. So you need to also send this 'text' parameter as part of your request.
Also your request type is currently '-X GET' and '-X' is actually just a parameter specifying request method for the curl command so you can skip that and just go with GET or just simply using method requests.get() .
1 2 |
payload = { 'text' : 'some text here' }
response = requests.get(url, headers = headers, data = payload)
|
Thanks for your reply. However,the code didn't work:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import requests
headers = {
'api_key' : "5268c1bfd9da46c996d50649b23b59f5" ,
'Cache-Control' : "no-cache"
}
payload = { 'text' : 'do la mot nguoi dan ba dam dang' }
response = requests.get(url,headers = headers, data = payload)
print (response.text)
|
I change the code to:
print(response)
This case is 504. I search this is:
Quote:504 - Gateway Timeout
How to solve that problem?
Posts: 95
Threads: 1
Joined: Apr 2018
Jan-14-2019, 09:17 AM
(This post was last modified: Jan-14-2019, 09:17 AM by mlieqo.)
Your request seems ok, if you're getting 504 then the problem should be on the server side - check a short explanation here: https://stackoverflow.com/a/8494758
Posts: 5
Threads: 2
Joined: Jan 2019
(Jan-14-2019, 09:17 AM)mlieqo Wrote: Your request seems ok, if you're getting 504 then the problem should be on the server side - check a short explanation here: https://stackoverflow.com/a/8494758 I got it but is there anyway to fix it?
Posts: 95
Threads: 1
Joined: Apr 2018
This can be fixed only by the people running the server so unfortunately there is nothing you can do at this point.
Posts: 5
Threads: 2
Joined: Jan 2019
Jan-15-2019, 11:50 AM
(This post was last modified: Jan-15-2019, 12:12 PM by manhsv.)
I've checked, the service of this API doesn't work.But this case is POST function. I've tried another API. May you do an example for this? API's documentation is here(my api_key is on the previous post). Thank in advance
If you don't know Vietnamese, I've translated it into English
Posts: 101
Threads: 7
Joined: Aug 2017
(Jan-15-2019, 11:50 AM)manhsv Wrote: I've checked, the service of this API doesn't work.But this case is POST function. I've tried another API. May you do an example for this? API's documentation is here(my api_key is on the previous post). Thank in advance
Example:
1 2 3 4 5 6 7 8 9 |
import requests
name = "Nguyễn Văn Tuấn"
headers = {
"Cache-Control" : "no-cache" ,
"api_key" : "5268c1bfd9da46c996d50649b23b59f5"
}
|
|