pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

create function with restful API,which has the error "415 Unsupported Media Type"

Open Kelly-ZH opened this issue 2 years ago • 3 comments

Hello, I met an error which needs help. I am looking forward someone can answer it, thank you. I create function which string like {"runtimeFlags":"","tenant":"public","namespace":"default","name":"PublishFunction","className":"org.apache.pulsar.functions.api.examples.PublishFunction","inputs":["persistent://public/default/function-input-topic"],"customSerdeInputs":{},"topicsPattern":"","customSchemaInputs":{},"customSchemaOutputs":{},"inputSpecs":{"persistent://public/default/function-input-topic":{"schemaType":"","serdeClassName":"","schemaProperties":{},"consumerProperties":{},"receiverQueueSize":0,"cryptoConfig":{},"poolMessages":true,"regexPattern":true}},"output":"persistent://public/default/function-output-topic","producerConfig":{"maxPendingMessages":0,"maxPendingMessagesAcrossPartitions":0,"useThreadLocalProducers":true,"cryptoConfig":{},"batchBuilder":""},"outputSchemaType":"","outputSerdeClassName":"","logTopic":"","processingGuarantees":"ATLEAST_ONCE","retainOrdering":true,"retainKeyOrdering":true,"batchBuilder":"","forwardSourceMessageProperty":true,"userConfig":{},"secrets":{},"runtime":"JAVA","autoAck":true,"maxMessageRetries":0,"deadLetterTopic ":"","subName ":"","parallelism ":2,"resources ":{"cpu ":1.0,"ram ":1073741824,"disk ":10737418240},"fqfn ":"","windowConfig ":{},"timeoutMs ":0,"jar ":"/opt/cloud/GEMASPulsar/apache-pulsar-2.10.0/examples/api-examples.jar","py ":"","go ":"","cleanupSubscription ":true,"customRuntimeOptions ":"","maxPendingAsyncRequests ":0,"exposePulsarAdminClientEnabled ":true,"subscriptionPosition ":"Latest "}, I also try make above string as a json file, but it doesn't work; Then I set Content-Type as application/json or "multipart/form-data".

the detail error is bellow: `Note: Unnecessary use of -X or --request, POST is already inferred.

  • Trying 10.172.167.163:8080...
  • Connected to 10.172.167.163 (10.172.167.163) port 8080 (#0)

POST /admin/v3/functions/public/default/PublishFunction HTTP/1.1 Host: 10.172.167.163:8080 User-Agent: curl/7.69.1 Accept: / Content-Type: application/json;charset=utf-8 Content-Length: 1447

  • upload completely sent off: 1447 out of 1447 bytes
  • Mark bundle as not supporting multiuse < HTTP/1.1 415 Unsupported Media Type < Date: Sat, 16 Jul 2022 11:05:25 GMT < Cache-Control: must-revalidate,no-cache,no-store < Content-Type: text/html;charset=iso-8859-1 < Server: Jetty(9.4.43.v20210629) < Content-Length: 579 <
Error 415 Unsupported Media Type

HTTP ERROR 415 Unsupported Media Type

URI:/admin/v3/functions/public/default/PublishFunction
STATUS:415
MESSAGE:Unsupported Media Type
SERVLET:org.glassfish.jersey.servlet.ServletContainer-70a24463

Powered by Jetty:// 9.4.43.v20210629
`

Kelly-ZH avatar Jul 16 '22 11:07 Kelly-ZH

Hello, someone can help me to solve the problem?

Kelly-ZH avatar Jul 18 '22 01:07 Kelly-ZH

The issue had no activity for 30 days, mark with Stale label.

github-actions[bot] avatar Aug 17 '22 02:08 github-actions[bot]

Hello, someone can help me to solve the problem?

you can use curl like below

curl --location --request POST 'http://127.0.0.1:8080/admin/v3/functions/sample/ns1/toupper' \
--header 'Content-Disposition;' \
--form 'data=@"/Users/zy/01_prj/pulsar/func/uppercase.py"' \
--form 'functionConfig=@"/Users/zy/01_prj/pulsar/func/upper.json"'

or python script below

import requests

url = "http://127.0.0.1:8080/admin/v3/functions/sample/ns1/toupper"

payload={}
files=[
  ('data',('uppercase.py',open('/Users/zy/01_prj/pulsar/func/uppercase.py','rb'),'application/octet-stream')),
  ('functionConfig',('upper.json',open('/Users/zy/01_prj/pulsar/func/upper.json','rb'),'application/json'))
]
headers = {
  'Content-Disposition': ''
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

kingdom998 avatar Sep 20 '22 02:09 kingdom998

The issue had no activity for 30 days, mark with Stale label.

github-actions[bot] avatar Oct 22 '22 02:10 github-actions[bot]