couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hank Knight <hknight...@gmail.com>
Subject Re: CouchDB: @ in username messing up curl
Date Thu, 14 Nov 2013 16:59:40 GMT
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 <dch@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
>

Mime
View raw message