-
Notifications
You must be signed in to change notification settings - Fork 439
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Which Cloudflare product(s) does this pertain to?
Workers/Other
What version of Wrangler
are you using?
3.1.0
What operating system are you using?
Mac
Describe the Bug
It is impossible to query deepl API from workers.
The bug was first mentioned in August 2021 on the forum. It was stated that "this is typically caused by a configuration issue in the origin web server". I opened a corresponding issue in their repo and they concluded that "the problem lies with cloudflare workers". Can you take a look at this problem? Other services might be unreachable as well.
Deepl is a very popular product and it is sad that it can be used with workers.
Code to reproduce
const deepLUrl = 'https://api-free.deepl.com/v2/translate'
const text = 'I like my cat'
const to = 'de'
const from = 'en'
const resp = await fetch(deepLUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `DeepL-Auth-Key ${env.DEEPL}`,
},
body: `text=${encodeURIComponent(text)}&target_lang=${to.toUpperCase()}&source_lang=${from.toUpperCase()}`,
})
if (!resp.ok) throw new Error(`DeepL error (${resp.status}) ` + resp.statusText) // throws in workers
const response = await resp.json()
response.translations[0].text // works in node
fetimo and muratcankaracabey
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working