You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Hank Knight <hk...@gmail.com> on 2013/11/14 03:03:54 UTC

CouchDB: @ in username messing up curl

What is wrong with this?

curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
 https://zqzqzqz555.couchappy.com/urls \
 -d "{}" -H "Content-Type: application/json"

I get an error:
curl: (6) Couldn't resolve host 'sharklasers.com:password123'

I think the problem is because of the @ in the username.  How can this be fixed?

The database, username and password in the example above are all real
so you may test it verbatim.

Thanks!

Re: CouchDB: @ in username messing up curl

Posted by Steven Anderson <sa...@salesforce.com>.
You need to percent encode it - @ is %40


On Wed, Nov 13, 2013 at 6:32 PM, Hank Knight <hk...@gmail.com> wrote:

> The username is
> nlbdmobz@sharklasers.com
>
> And the password is
> password123
>
> Please test it:
> https://zqzqzqz555.couchappy.com/
>
> Putting the password in the middle of the username does NOT work.
>
> The real question relates to escaping the @.
>
> Believe me, I have spent quite a bit of time Googling this and found
> nothing.
>
>
>
>
>
> On Wed, Nov 13, 2013 at 10:15 PM, Jens Alfke <je...@couchbase.com> wrote:
> >
> > On Nov 13, 2013, at 6:03 PM, Hank Knight <hk...@gmail.com> wrote:
> >
> >> What is wrong with this?
> >>
> >> curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
> >> https://zqzqzqz555.couchappy.com/urls \
> >> -d "{}" -H "Content-Type: application/json"
> >>
> >> I get an error:
> >> curl: (6) Couldn't resolve host 'sharklasers.com:password123'
> >
> > Wrong syntax. It should be nlbdmobz:password123@sharklasers.com .
> >
> > The syntax is weird, but it’s really not hard to find out how it works.
> Try googling for [url password syntax] and the top few hits all look like
> good info.
> >
> > —Jens
>



-- 

     Steve

Re: CouchDB: @ in username messing up curl

Posted by Stanley Iriele <si...@gmail.com>.
Try generating the basic with header yourself
On Nov 13, 2013 6:43 PM, "Hank Knight" <hk...@gmail.com> wrote:

> I tried encoding the @ but that does not work either!
>
> curl -kX -u nlbdmobz%40sharklasers.com:password123 POST \
>  https://zqzqzqz555.couchappy.com/urls \
>  -d "{}" -H "Content-Type: application/json"
>
> Please test it with the real database and login information I provided.
>
> Unfortunately I have to use curl here and I need to figure out what to
> do about "@".
>
> Thanks for the help!
>
>
> On Wed, Nov 13, 2013 at 10:36 PM, Stanley Iriele <si...@gmail.com>
> wrote:
> > Yeah that's a funny case...I usually avoid doing that for that specific
> > reason... Why not base64 encode it and send the file in a formatted
> header
> > yourself instead of relying  on curl?...
> > On Nov 13, 2013 6:32 PM, "Hank Knight" <hk...@gmail.com> wrote:
> >
> >> The username is
> >> nlbdmobz@sharklasers.com
> >>
> >> And the password is
> >> password123
> >>
> >> Please test it:
> >> https://zqzqzqz555.couchappy.com/
> >>
> >> Putting the password in the middle of the username does NOT work.
> >>
> >> The real question relates to escaping the @.
> >>
> >> Believe me, I have spent quite a bit of time Googling this and found
> >> nothing.
> >>
> >>
> >>
> >>
> >>
> >> On Wed, Nov 13, 2013 at 10:15 PM, Jens Alfke <je...@couchbase.com>
> wrote:
> >> >
> >> > On Nov 13, 2013, at 6:03 PM, Hank Knight <hk...@gmail.com>
> wrote:
> >> >
> >> >> What is wrong with this?
> >> >>
> >> >> curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
> >> >> https://zqzqzqz555.couchappy.com/urls \
> >> >> -d "{}" -H "Content-Type: application/json"
> >> >>
> >> >> I get an error:
> >> >> curl: (6) Couldn't resolve host 'sharklasers.com:password123'
> >> >
> >> > Wrong syntax. It should be nlbdmobz:password123@sharklasers.com .
> >> >
> >> > The syntax is weird, but it’s really not hard to find out how it
> works.
> >> Try googling for [url password syntax] and the top few hits all look
> like
> >> good info.
> >> >
> >> > —Jens
> >>
>

Re: CouchDB: @ in username messing up curl

Posted by Hank Knight <hk...@gmail.com>.
I tried encoding the @ but that does not work either!

curl -kX -u nlbdmobz%40sharklasers.com:password123 POST \
 https://zqzqzqz555.couchappy.com/urls \
 -d "{}" -H "Content-Type: application/json"

Please test it with the real database and login information I provided.

Unfortunately I have to use curl here and I need to figure out what to
do about "@".

Thanks for the help!


On Wed, Nov 13, 2013 at 10:36 PM, Stanley Iriele <si...@gmail.com> wrote:
> Yeah that's a funny case...I usually avoid doing that for that specific
> reason... Why not base64 encode it and send the file in a formatted header
> yourself instead of relying  on curl?...
> On Nov 13, 2013 6:32 PM, "Hank Knight" <hk...@gmail.com> wrote:
>
>> The username is
>> nlbdmobz@sharklasers.com
>>
>> And the password is
>> password123
>>
>> Please test it:
>> https://zqzqzqz555.couchappy.com/
>>
>> Putting the password in the middle of the username does NOT work.
>>
>> The real question relates to escaping the @.
>>
>> Believe me, I have spent quite a bit of time Googling this and found
>> nothing.
>>
>>
>>
>>
>>
>> On Wed, Nov 13, 2013 at 10:15 PM, Jens Alfke <je...@couchbase.com> wrote:
>> >
>> > On Nov 13, 2013, at 6:03 PM, Hank Knight <hk...@gmail.com> wrote:
>> >
>> >> What is wrong with this?
>> >>
>> >> curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
>> >> https://zqzqzqz555.couchappy.com/urls \
>> >> -d "{}" -H "Content-Type: application/json"
>> >>
>> >> I get an error:
>> >> curl: (6) Couldn't resolve host 'sharklasers.com:password123'
>> >
>> > Wrong syntax. It should be nlbdmobz:password123@sharklasers.com .
>> >
>> > The syntax is weird, but it’s really not hard to find out how it works.
>> Try googling for [url password syntax] and the top few hits all look like
>> good info.
>> >
>> > —Jens
>>

Re: CouchDB: @ in username messing up curl

Posted by Stanley Iriele <si...@gmail.com>.
Yeah that's a funny case...I usually avoid doing that for that specific
reason... Why not base64 encode it and send the file in a formatted header
yourself instead of relying  on curl?...
On Nov 13, 2013 6:32 PM, "Hank Knight" <hk...@gmail.com> wrote:

> The username is
> nlbdmobz@sharklasers.com
>
> And the password is
> password123
>
> Please test it:
> https://zqzqzqz555.couchappy.com/
>
> Putting the password in the middle of the username does NOT work.
>
> The real question relates to escaping the @.
>
> Believe me, I have spent quite a bit of time Googling this and found
> nothing.
>
>
>
>
>
> On Wed, Nov 13, 2013 at 10:15 PM, Jens Alfke <je...@couchbase.com> wrote:
> >
> > On Nov 13, 2013, at 6:03 PM, Hank Knight <hk...@gmail.com> wrote:
> >
> >> What is wrong with this?
> >>
> >> curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
> >> https://zqzqzqz555.couchappy.com/urls \
> >> -d "{}" -H "Content-Type: application/json"
> >>
> >> I get an error:
> >> curl: (6) Couldn't resolve host 'sharklasers.com:password123'
> >
> > Wrong syntax. It should be nlbdmobz:password123@sharklasers.com .
> >
> > The syntax is weird, but it’s really not hard to find out how it works.
> Try googling for [url password syntax] and the top few hits all look like
> good info.
> >
> > —Jens
>

Re: CouchDB: @ in username messing up curl

Posted by Hank Knight <hk...@gmail.com>.
The username is
nlbdmobz@sharklasers.com

And the password is
password123

Please test it:
https://zqzqzqz555.couchappy.com/

Putting the password in the middle of the username does NOT work.

The real question relates to escaping the @.

Believe me, I have spent quite a bit of time Googling this and found nothing.





On Wed, Nov 13, 2013 at 10:15 PM, Jens Alfke <je...@couchbase.com> wrote:
>
> On Nov 13, 2013, at 6:03 PM, Hank Knight <hk...@gmail.com> wrote:
>
>> What is wrong with this?
>>
>> curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
>> https://zqzqzqz555.couchappy.com/urls \
>> -d "{}" -H "Content-Type: application/json"
>>
>> I get an error:
>> curl: (6) Couldn't resolve host 'sharklasers.com:password123'
>
> Wrong syntax. It should be nlbdmobz:password123@sharklasers.com .
>
> The syntax is weird, but it’s really not hard to find out how it works. Try googling for [url password syntax] and the top few hits all look like good info.
>
> —Jens

Re: CouchDB: @ in username messing up curl

Posted by Jens Alfke <je...@couchbase.com>.
On Nov 13, 2013, at 6:03 PM, Hank Knight <hk...@gmail.com> wrote:

> What is wrong with this?
> 
> curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
> https://zqzqzqz555.couchappy.com/urls \
> -d "{}" -H "Content-Type: application/json"
> 
> I get an error:
> curl: (6) Couldn't resolve host 'sharklasers.com:password123'

Sorry, I was confused by the cryptic command line at first and thought you were trying to embed credentials in a URL.

Your real problem has nothing to do with the ‘@‘ sign. You’ve stuck the username argument in between the -X flag and the method name that’s supposed to follow it. If you just move the -X and POST next to each other, it works fine:

$ curl -k -u nlbdmobz@sharklasers.com:password123 -X POST https://zqzqzqz555.couchappy.com/urls -d "{}" -H "Content-Type: application/json"
{"ok":true,"id":"2bac0dff04ebbfcbecb1d491e9000dda","rev":"1-967a00dff5e02add41819138abb3284d”}

—Jens



Re: CouchDB: @ in username messing up curl

Posted by Jens Alfke <je...@couchbase.com>.
On Nov 13, 2013, at 6:03 PM, Hank Knight <hk...@gmail.com> wrote:

> What is wrong with this?
> 
> curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
> https://zqzqzqz555.couchappy.com/urls \
> -d "{}" -H "Content-Type: application/json"
> 
> I get an error:
> curl: (6) Couldn't resolve host 'sharklasers.com:password123'

Wrong syntax. It should be nlbdmobz:password123@sharklasers.com .

The syntax is weird, but it’s really not hard to find out how it works. Try googling for [url password syntax] and the top few hits all look like good info.

—Jens

Re: CouchDB: @ in username messing up curl

Posted by Dave Cottlehuber <dc...@jsonified.com>.
On 14. November 2013 at 18:01:00, Hank Knight (hknight555@gmail.com) wrote:
>  
> Thanks, guys.
>  
> You were right, the problem was not actually the @!
>  
> This works:
>  
> curl -k -u nlbdmobz@sharklasers.com:password123 \
> -X POST https://zqzqzqz555.couchappy.com/urls \
> -d "{}" -H "Content-Type: application/json"

Yay!

I note there’s still no -v flag in there thought ;-)

And don’t forget to try out httpie. You’ll never go back, I promise.

A+
D


Re: CouchDB: @ in username messing up curl

Posted by Hank Knight <hk...@gmail.com>.
Thanks, guys.

You were right, the problem was not actually the @!

This works:

curl -k -u nlbdmobz@sharklasers.com:password123 \
 -X POST https://zqzqzqz555.couchappy.com/urls \
 -d "{}" -H "Content-Type: application/json"

On Thu, Nov 14, 2013 at 4:49 AM, Dave Cottlehuber <dc...@jsonified.com> wrote:
> On 14. November 2013 at 03:04:22, Hank Knight (hknight555@gmail.com) wrote:
>>
>> What is wrong with this?
>
>
> The main error is that you’re not using `curl -v…` by default.
>
> If so you’d see:
>
> curl -vkX -u nlbdmobz\%40sharklasers.com:password123 POST https://zqzqzqz555.couchappy.com/urls -d "{}" -H "Content-Type: application/json"
> * Rebuilt URL to: nlbdmobz%40sharklasers.com:password123/
> * Adding handle: conn: 0x7f962981ba00
> * Adding handle: send: 0
> * Adding handle: recv: 0
> * Curl_addHandleToPipeline: length: 1
> * - Conn 0 (0x7f962981ba00) send_pipe: 1, recv_pipe: 0
> * Could not resolve: nlbdmobz%40sharklasers.com (Could not contact DNS servers)
> * Closing connection 0
>
>
> Aha!!!
>
>> curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
>> https://zqzqzqz555.couchappy.com/urls \
>> -d "{}" -H "Content-Type: application/json"
>>
>> I get an error:
>> curl: (6) Couldn't resolve host 'sharklasers.com:password123'
>>
>> I think the problem is because of the @ in the username. How can
>> this be fixed?
>>
>> The database, username and password in the example above are
>> all real
>> so you may test it verbatim.
>>
>> Thanks!
>
> The error message is insightful (once you know what you’re looking for!)
>
>     couldn't resolve host 'sharklasers.com:password123’
>
> Your curl parameters are in the wrong order, and what you think is being
> used as the arguments to -u are being picked up by the -X parameter first,
> and parsed as the hostname.
>
> Fix that and it works.
>
> I find with curl & couchdb you need to split out auth from other operations, i.e. get auth working with GET /, and then add in your posts or views.
>
> Also for console testing of couchdb, I highly recommend the amazing http://httpie.org/ python tool:
>
> ```shell
> $ pip install httpie
> $  http --verify=no --json --pretty all --verbose --style fruity \
>     --auth-type basic --auth nlbdmobz@sharklasers.com:password123 \
>     get https://zqzqzqz555.couchappy.com/
>
> GET / HTTP/1.1
> Accept: application/json
> Accept-Encoding: gzip, deflate, compress
> Authorization: Basic bmxiZG1vYnpAc2hhcmtsYXNlcnMuY29tOnBhc3N3b3JkMTIz
> Content-Type: application/json; charset=utf-8
> Host: zqzqzqz555.couchappy.com
> User-Agent: HTTPie/0.8.0-dev
>
> HTTP/1.1 200 OK
> Cache-Control: must-revalidate
> Content-Length: 151
> Content-Type: application/json
> Date: Thu, 14 Nov 2013 08:42:49 GMT
> Server: CouchDB/1.3.0 (Erlang OTP/R15B01)
>
> {
>     "couchdb": "Welcome to Couchappy",
>     "uuid": "040ec65fed39bc70c14f8f7dc1a0c8b6",
>     "vendor": {
>         "name": "www.couchappy.com",
>         "version": "1.3.0"
>     },
>     "version": "1.3.0"
> }
> ```
>
> Now you can add in your POST parameters safely.
>
> A+
> Dave
>

Re: CouchDB: @ in username messing up curl

Posted by Jens Alfke <je...@couchbase.com>.
On Nov 14, 2013, at 12:49 AM, Dave Cottlehuber <dc...@jsonified.com> wrote:

> Also for console testing of couchdb, I highly recommend the amazing http://httpie.org/ python tool:

+1. I was going to mention this in my previous reply but forgot. httpie is custom-made for working with JSON-based REST APIs. Here’s how easy it is to create a document:
	$ http PUT :5984/db/doc prop1=value1 prop2=value2
Bang, that’s it. It automatically converts the “name=value” pairs to JSON and sets the Content-Type.
It also pretty-prints JSON responses and has a lot of other features that will brighten your day.

—Jens

Re: CouchDB: @ in username messing up curl

Posted by Dave Cottlehuber <dc...@jsonified.com>.
On 14. November 2013 at 03:04:22, Hank Knight (hknight555@gmail.com) wrote:
>  
> What is wrong with this?


The main error is that you’re not using `curl -v…` by default.

If so you’d see:

curl -vkX -u nlbdmobz\%40sharklasers.com:password123 POST https://zqzqzqz555.couchappy.com/urls -d "{}" -H "Content-Type: application/json"
* Rebuilt URL to: nlbdmobz%40sharklasers.com:password123/
* Adding handle: conn: 0x7f962981ba00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f962981ba00) send_pipe: 1, recv_pipe: 0
* Could not resolve: nlbdmobz%40sharklasers.com (Could not contact DNS servers)
* Closing connection 0


Aha!!!

> curl -kX -u nlbdmobz@sharklasers.com:password123 POST \
> https://zqzqzqz555.couchappy.com/urls \
> -d "{}" -H "Content-Type: application/json"
>  
> I get an error:
> curl: (6) Couldn't resolve host 'sharklasers.com:password123'  
>  
> I think the problem is because of the @ in the username. How can  
> this be fixed?
>  
> The database, username and password in the example above are  
> all real
> so you may test it verbatim.
>  
> Thanks!

The error message is insightful (once you know what you’re looking for!)

    couldn't resolve host 'sharklasers.com:password123’ 

Your curl parameters are in the wrong order, and what you think is being
used as the arguments to -u are being picked up by the -X parameter first,
and parsed as the hostname.

Fix that and it works.

I find with curl & couchdb you need to split out auth from other operations, i.e. get auth working with GET /, and then add in your posts or views.

Also for console testing of couchdb, I highly recommend the amazing http://httpie.org/ python tool:

```shell
$ pip install httpie
$  http --verify=no --json --pretty all --verbose --style fruity \
    --auth-type basic --auth nlbdmobz@sharklasers.com:password123 \
    get https://zqzqzqz555.couchappy.com/

GET / HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Authorization: Basic bmxiZG1vYnpAc2hhcmtsYXNlcnMuY29tOnBhc3N3b3JkMTIz
Content-Type: application/json; charset=utf-8
Host: zqzqzqz555.couchappy.com
User-Agent: HTTPie/0.8.0-dev

HTTP/1.1 200 OK
Cache-Control: must-revalidate
Content-Length: 151
Content-Type: application/json
Date: Thu, 14 Nov 2013 08:42:49 GMT
Server: CouchDB/1.3.0 (Erlang OTP/R15B01)

{
    "couchdb": "Welcome to Couchappy",
    "uuid": "040ec65fed39bc70c14f8f7dc1a0c8b6",
    "vendor": {
        "name": "www.couchappy.com",
        "version": "1.3.0"
    },
    "version": "1.3.0"
}
```

Now you can add in your POST parameters safely.

A+
Dave