我创建了一个Plumber API,该API接受base64编码的字符串并从中提取数据,将其转换为数据框,然后将数据作为JSON返回。问题是在Swagger和Postman上进行测试时,我得到的响应不一致。发送请求时,我通常会收到响应404-找不到资源,但是我时不时地返回200响应,其中包含以JSON正确提供的数据。
供参考:base64编码的字符串对应于此document
的第一页水管工代码是:
# plumber.R
#* Echo back the input
#* @param encoded_data Base-64 encoded_data pdf
#* @get /extractAML
function(encoded_data){
library(tidyverse)
library(pdftools)
library(base64enc)
input <- strsplit(rawToChar(base64decode(encoded_data)), "\n")
df <- data.frame(key = input[[1]], value = lead(input[[1]],1))
index <- which(grepl("^[0-9]{1,2}\\.",df$key))
df <- df[index,]
df <- df %>% slice(1:10)
df
}
然后我运行
r <- plumb("plumber.R")
r$run(port=8002)
公开API。
我在Swagger页面上使用“尝试一下”,然后粘贴base64编码的字符串,然后执行。最初返回404,但尝试了更多次(可能是10次,可能是20次)后,我得到了成功的呼叫。 JSON如下所示。但是几秒钟后,我再次单击“执行”,并再次获得202响应。
[
{
"key": "1. Name of Institution Completing\r",
"value": " East West Bank\r"
},
{
"key": "2. Date Completed:\r",
"value": " March 13th 2018\r"
},
{
"key": "3. Completed by:\r",
"value": " Name: Myrna Olvera\r"
},
{
"key": "4. Date Established:\r",
"value": " January 1, 1972\r"
},
{
"key": "5. Number of Branches:\r",
"value": " 120+ in USA, 1 branch in Hong Kong and 2 representative offices in\r"
},
{
"key": "6. Type of Business: Commercial and Personal Banking\r",
"value": "7. Registration Certificate No./License No.:\r"
},
{
"key": "7. Registration Certificate No./License No.:\r",
"value": " Federal Reserve ID #197478, FDIC # 31628, CA DFI #1748\r"
},
{
"key": "8. Address:\r",
"value": " 135 North Los Robles Avenue, California, CA 91101, USA\r"
},
{
"key": "9. Principal Place of Business:\r",
"value": " 135 North Los Robles Avenue, California, CA 91101, USA\r"
},
{
"key": "10. Location Of The Head Office:\r",
"value": " 135 North Los Robles Avenue, California, CA 91101, USA\r"
}
]
我尝试在Postman中运行API调用并获得相同的结果-大多数情况下,我会收到404响应,但偶尔会返回预期的json。当我在bash中运行curl时也是如此。
完整的Curl语句为:
curl -X GET "http://127.0.0.1:8002/extractAML?encoded_data=ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEFNTC9LWUMgUXVlc3Rpb25uYWlyZSBGb3JtDQpBbnRpLU1vbmV5IExhdW5kZXJpbmcgUXVlc3Rpb25uYWlyZQ0KSS4gQ29ycG9yYXRlIEluZm9ybWF0aW9uOg0KMS4gTmFtZSBvZiBJbnN0aXR1dGlvbiBDb21wbGV0aW5nDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEVhc3QgV2VzdCBCYW5rDQogICAgIFF1ZXN0aW9ubmFpcmU6DQoyLiBEYXRlIENvbXBsZXRlZDoNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgTWFyY2ggMTN0aCAyMDE4DQozLiBDb21wbGV0ZWQgYnk6DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIE5hbWU6ICAgICBNeXJuYSBPbHZlcmENCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgVGl0bGU6ICAgIFNlbmlvciBWaWNlIFByZXNpZGVudCwgQlNBIE9mZmljZXINCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgUG9zaXRpb246IEJTQSBPZmZpY2VyDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEVtYWlsOiAgICBNeXJuYS5PbHZlcmFARWFzdFdlc3RCYW5rLmNvbQ0KNC4gRGF0ZSBFc3RhYmxpc2hlZDoNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgSmFudWFyeSAxLCAxOTcyDQo1LiBOdW1iZXIgb2YgQnJhbmNoZXM6DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEyMCsgaW4gVVNBLCAxIGJyYW5jaCBpbiBIb25nIEtvbmcgYW5kIDIgcmVwcmVzZW50YXRpdmUgb2ZmaWNlcyBpbg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBDaGluYS4NCjYuIFR5cGUgb2YgQnVzaW5lc3M6ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQ29tbWVyY2lhbCBhbmQgUGVyc29uYWwgQmFua2luZw0KNy4gUmVnaXN0cmF0aW9uIENlcnRpZmljYXRlIE5vLi9MaWNlbnNlIE5vLjoNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgRmVkZXJhbCBSZXNlcnZlIElEICMxOTc0NzgsIEZESUMgIyAzMTYyOCwgQ0EgREZJICMxNzQ4DQo4LiBBZGRyZXNzOg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAxMzUgTm9ydGggTG9zIFJvYmxlcyBBdmVudWUsIENhbGlmb3JuaWEsIENBIDkxMTAxLCBVU0ENCjkuIFByaW5jaXBhbCBQbGFjZSBvZiBCdXNpbmVzczoNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgMTM1IE5vcnRoIExvcyBSb2JsZXMgQXZlbnVlLCBDYWxpZm9ybmlhLCBDQSA5MTEwMSwgVVNBDQoxMC4gTG9jYXRpb24gT2YgVGhlIEhlYWQgT2ZmaWNlOg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAxMzUgTm9ydGggTG9zIFJvYmxlcyBBdmVudWUsIENhbGlmb3JuaWEsIENBIDkxMTAxLCBVU0ENCjExLiBXZWJzaXRlIEFkZHJlc3M6DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHd3dy5lYXN0d2VzdGJhbmsuY29tDQpJSS4gT3duZXIvUGFyZW50IEluZm9ybWF0aW9uOg0KMTIuIExlZ2FsIEVudGl0eSBOYW1lIG9mIHBhcmVudCBjb21wYW55Og0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBFYXN0IFdlc3QgQmFuY29ycCwgSW5jLg0KMTMuIFBlcmNlbnRhZ2Ugb2Ygb3duZXJzaGlwIG9mIGNvbXBhbnk6DQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIDEwMCUNCklJSS4gT3duZXJzaGlwIFN0cnVjdHVyZToNCjE0LiBJcyB0aGUgRkkgd2hvbGx5IG9yIHBhcnRpYWxseSBvd25lZCBieSBhIHN0YXRlIGVudGl0eSBvciB0aGUgZ292ZXJubWVudD8gICAgICAgICAgICAgICAgICAgICAg4piQIFllcyAgICAgICAg4piSIE5vDQoxNS4gSXMgdGhlIEZJIHB1YmxpY2x5IG93bmVkIGFuZCBsaXN0ZWQgb24gYW55IFN0b2NrIEV4Y2hhbmdlPw0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICDimJIgWWVzICAgICAgICDimJAgTm8NCiAgICAgICAgICAgICAgIOKAoiBJZiB5ZXMsIHBsZWFzZSBwcm92aWRlIHRoZSBuYW1lIG9mIHRoZSBTdG9jayBFeGNoYW5nZTogTkFTREFRIFN0b2NrDQogICAgICAgICAgICAgICAgIEV4Y2hhbmdlIChTdG9jayBTeW1ib2w6IEVXQkMpDQogICAgICAgICAgICAgICDigKIgSWYgbm8sIHBsZWFzZSBhdHRhY2ggYSBsaXN0IG9mIHRoZSBiZW5lZmljaWFsIG93bmVyczEgb2YgdGhlIEZJIChpbmNsdWRpbmcgdGhlaXINCiAgICAgICAgICAgICAgICAgbm9taW5lZXMsIGlmIHRoZWlyIHNoYXJlcyBhcmUgaGVsZCBieSBub21pbmVlcykuDQoxNi4gUGxlYXNlIGNvbmZpcm0gd2hldGhlciBhbnkgb2YgdGhlIHByaW5jaXBhbCBvd25lcnMgb2YgdGhlIEZJIGlzIGNvbnNpZGVyZWQgYXMgUG9saXRpY2FsbHkNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg4piQIFllcyAgICAgICAg4piSIE5vDQogICAgIEV4cG9zZWQgUGVyc29uMi4NCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIFBhZ2UgMSBvZiA0DQo%3D" -H "accept: application/json"
有人知道为什么我会看到这种不一致的行为吗?我正在使用最新的可用水管工包装。