gpt4 book ai didi

android - 对curl的响应是从CircleCI上的gradle调用的空蜜蜂

转载 作者:行者123 更新时间:2023-12-03 05:30:50 24 4
gpt4 key购买 nike

我在gradle中有一个任务,该任务为android APP下载翻译

task('downloadTranslations') {
ext.downloadPOTranslation = { stringsFile, projectId, lang ->
def f = new File(stringsFile)
if (f.exists()) {
println("Delete file: " + f.absolutePath)
f.delete()
}

println("Get lang: " + lang + " for project: " + projectId)

def requestArray = ['curl', '-X', 'POST', "\"https://api.poeditor.com/v2/projects/export\"",
'-d', 'api_token=\"{API_KEY}\"',
'-d', 'id=\"' + projectId + '\"',
'-d', 'language=\"' + lang + '\"',
'-d', 'type=\"android_strings\"']

println(requestArray)
def request = requestArray.execute()

request.waitFor()
def response = request.text
if (response.isEmpty()) {
def errorResponse = request.err.text
println("Error response from server:")
println(errorResponse)
} else {
println("Response from server:")
println(response)
}

...

}

doLast {
downloadPOTranslation("src/main/res/values/strings.xml", "projectNumber", "en-gb")
}

}

当我从CLI或Android Studio的本地计算机调用此任务时,一切正常:
Get lang: en-gb for project: 250751
[curl, -X, POST, "https://api.poeditor.com/v2/projects/export", -d, api_token="API_TOKEN", -d, id="250751", -d, language="en-gb", -d, type="android_strings"]
Response from server:
{"response":{"status":"success","code":"200","message":"OK"},"result":{"url":"https:\/\/api.poeditor.com\/v2\/download\/file\/FILENUMBER"}}

但是,当我在CircleCI上尝试完全相同时,出现错误:
Get lang: en-gb for project: 250751
[curl, -X, POST, "https://api.poeditor.com/v2/projects/export", -d, api_token="API_TOKEN", -d, id="250751", -d, language="en-gb", -d, type="android_strings"]

FAILURE: Build failed with an exception.

* Where:
Build file '/home/circleci/code/app/build.gradle' line: 204

* What went wrong:
Execution failed for task ':app:downloadTranslations'.
> java.io.IOException: Stream closed

由于 response.isEmpty()truerequest.err已关闭,因此发生了流关闭。

那么 为什么可以这样使Gradle在本地工作时从服务器获取空响应?

我还尝试了SSH到CircleCI并直接从CLI运行curl-响应不为空。

最佳答案

问题出在'"之间。

我不知道为什么,但是'curl'可能被忽略了。

所以

    def requestArray = ["curl",
"-X", "POST",
"-d","api_token=API_KEY",
"-d", "id=" + projectId + "",
"-d", "language=" + lang + "",
"-d", "type=android_strings",
"https://api.poeditor.com/v2/projects/export",]

工作正常。

关于android - 对curl的响应是从CircleCI上的gradle调用的空蜜蜂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59414480/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com