curl: (3) unmatched brace in URL position 1:

I am running an Apache Solr tutorial from here:

Solr is running and I can run queries in a web browser.

The tutorial mentions cURL which I am unfamiliar with.

I have unzipped CURL to C:\Curl and included Curl in the PATH environment variable: C:\Curl\curl-7.63.0-win64-mingw\bin

I am getting an error when running the Command below in a Windows command prompt. I have googled to try and find a resolution to no avail:

Code below:

C:\Curl\curl-7.63.0-win64-mingw\bin>curl -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' 

generates the following error:

curl: (3) unmatched brace in URL position 1: {name:name, ^ curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL curl: (3) unmatched close brace/bracket in URL position 12: stored:true}}' ^ { "responseHeader":{ "status":400, "QTime":1}, "error":{ "metadata":[ "error-class","org.apache.solr.common.SolrException", "root-error-class","org.apache.solr.common.SolrException"], "msg":"no stream", "code":400}} 

I tried adding a -g to turn off globbing.

curl -g -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' 

This generated an almost identical error:

C:\Curl\curl-7.63.0-win64-mingw\bin>curl -g -X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL { "responseHeader":{ "status":400, "QTime":1}, "error":{ "metadata":[ "error-class","org.apache.solr.common.SolrException", "root-error-class","org.apache.solr.common.SolrException"], "msg":"no stream", "code":400}} 

I then tried removing the single quotes and escaping the double quotes, but then got the below error:

curl -g -X POST -H Content-type:application/json --data-binary {\"add-field\": {\"name\":\"name\", \"type\":\"text_general\", \"multiValued\":false, \"stored\":true}} 

curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL curl: (3) URL using bad/illegal format or missing URL { "responseHeader":{ "status":500, "QTime":4}, "error":{ "msg":"Premature EOF: char=(EOF),position=11 AFTER=''", "trace":"org.noggit.JSONParser$ParseException: Premature EOF: char=(EOF),position=11 AFTER=''\r\n\tat org.noggit.JSONParser.err(JSONParser.java:419)\r\n\tat org.noggit.JSONParser.next(JSONParser.j ava:973)\r\n\tat org.noggit.JSONParser.nextEvent(JSONParser.java:1061)\r\n\tat org.apache.solr.common.util.CommandOperation.parse(CommandOperation.java:285)\r\n\tat org.apache.solr.common.util.Command Operation.readCommands(CommandOperation.java:350)\r\n\tat org.apache.solr.common.util.CommandOperation.readCommands(CommandOperation.java:326)\r\n\tat org.apache.solr.api.ApiBag.getCommandOperations(A piBag.java:289)\r\n\tat org.apache.solr.servlet.HttpSolrCall.getCommands(HttpSolrCall.java:1073)\r\n\tat org.apache.solr.servlet.SolrRequestParsers$1.getCommands(SolrRequestParsers.java:245)\r\n\tat o rg.apache.solr.schema.SchemaManager.performOperations(SchemaManager.java:77)\r\n\tat org.apache.solr.handler.SchemaHandler.handleRequestBody(SchemaHandler.java:90)\r\n\tat org.apache.solr.handler.Requ estHandlerBase.handleRequest(RequestHandlerBase.java:199)\r\n\tat org.apache.solr.core.SolrCore.execute(SolrCore.java:2541)\r\n\tat org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:709)\ r\n\tat org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:515)\r\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:377)\r\n\tat org.apache.solr.servlet.SolrDi spatchFilter.doFilter(SolrDispatchFilter.java:323)\r\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doHa ndle(ServletHandler.java:533)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)\r\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)\ r\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)\r\n\tat org.eclipse.je tty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)\r\n\tat org.eclipse.jetty.server.handler. ContextHandler.doHandle(ContextHandler.java:1317)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(Serv letHandler.java:473)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)\ r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1219)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)\r\n\tat org.eclipse.jett y.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:219)\r\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)\r\n\tat org.eclipse.je tty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)\r\n\tat org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:335)\r\n\tat org.eclipse.jetty.server.handler.Hand lerWrapper.handle(HandlerWrapper.java:132)\r\n\tat org.eclipse.jetty.server.Server.handle(Server.java:531)\r\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)\r\n\tat org.eclipse .jetty.server.HttpConnection.onFillable(HttpConnection.java:260)\r\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)\r\n\tat org.eclipse.jetty.io.FillIn terest.fillable(FillInterest.java:102)\r\n\tat org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill .java:333)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java :168)\r\n\tat org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)\r\n\tat org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor. java:366)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:762)\r\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:680)\r\n\tat java. lang.Thread.run(Unknown Source)\r\n", "code":500}}

I know there are a lot of similar Q&A's on SO regarding this issue but they are not quite the same and none of the solutions I have tried resolve my issue.

5 Answers

I replaced the single quotes with double quote and escaped the double quotes inside the curly braces with a backslash and it has worked.

I went from this:

curl --X POST -H 'Content-type:application/json' --data-binary '{"add-field": {"name":"name", "type":"text_general", "multiValued":false, "stored":true}}' 

to this:

curl --X POST -H "Content-type:application/json" --data-binary "{\"add-field\": {\"name\":\"name\", \"type\":\"text_general\", \"multiValued\":false, \"stored\":true}}" 

Thank you everybody for your collective answers. I am sure there are some possible positives to adding the JSON to a separate file but i wanted to avoid the creation of additional files.

The Windows command prompt doesn't support single quotes. It's a problem because cURL statements use single quotes to specify JSON data.

To fix the problem, save the JSON in a separate file (e.g. add-field.txt) and import it into the cURL statement, so later you could run it like this:

curl -X POST -H 'Content-type:application/json' --data-binary @add-field.txt 
1

I would go another route. If you install Microsoft's wonderfool tool WSL. You will be able to run all those commands as is, as you will be running inside a linux system. It will be a big time saver eventually.

Gitbash solved it for me. WSL was crashing for a reason I ignore at the moment.

I found that this worked for me:

curl -X POST -H 'Content-type:application/json' --data "$DATA" 

Where $DATA is a shell varible containing JSON data and is enclosed in doub;e-quotes. This was in a Linux environment where I was having the same issue.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like