Bottom Page

Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Bad request(400) error!
#1
I try to add Vietnamese accent by using API on this :link((on API: Add Accents) but bad request(400).
import requests
url = "http://api.openfpt.vn/vnaccent/add"

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. Rolleyes
Larz60+ wrote Jan-13-2019, 06:00 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Added for you this time, please use bbcode tags on future posts.
Quote
#2
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
Quote
#3
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() .

payload = {'text': 'some text here'}
response = requests.get(url, headers=headers, data=payload)
Quote
#4
(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() .

payload = {'text': 'some text here'}
response = requests.get(url, headers=headers, data=payload)
Thanks for your reply. However,the code didn't work:
import requests
url = "http://api.openfpt.vn/vnaccent/add"

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? Blush
Quote
#5
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
Quote
#6
(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?
Quote
#7
This can be fixed only by the people running the server so unfortunately there is nothing you can do at this point.
Quote
#8
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
İmage
Quote
#9
(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:
import requests

name = "Nguyễn Văn Tuấn"
headers={
    "Cache-Control": "no-cache",
    "api_key": "5268c1bfd9da46c996d50649b23b59f5"
    }

r = requests.post('http://api.openfpt.vn/name2gender/json', headers=header, data = name.encode('utf-8'))
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  urllib request error 404 Coco 2 1,209 May-11-2019, 02:47 PM
Last Post: Larz60+
  Error in request, cache key a21250450 2 479 Apr-02-2019, 11:20 AM
Last Post: a21250450

Forum Jump:


Users browsing this thread: 1 Guest(s)