function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Base Line 7Base Line 7 

Problem with connecting to org using curl (Trailhead - Apex Web Services module)

I tried following the instructions given in the module (https://trailhead.salesforce.com/content/learn/modules/apex_integration_services/apex_integration_webservices). The code for connecting to the org using curl is as follows: 

curl -v https://login.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=<your_consumer_key>" -d "client_secret=<your_consumer_secret>" -d "username=<your_username>" -d "password=<your_password_and_security_token>" -H 'X-PrettyPrint:1'

I supplied all the credentials needed in the curl command but I keep getting this error whenever I execute the command: 

{"error":"invalid_grant","error_description":"authentication failure"}* Connection #0 to host test.salesforce.com left intact

The result in full is as follows:

*   Trying 101.53.168.24:443...
* TCP_NODELAY set
* Connected to login.salesforce.com (101.53.168.24) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: C:\curl\curl-ca-bundle.crt
  CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
*  subject: C=US; ST=California; L=San Francisco; O=salesforce.com, inc.; OU=InfraSec; CN=login.salesforce.com
*  start date: Dec 15 00:00:00 2017 GMT
*  expire date: Dec 14 12:00:00 2020 GMT
*  subjectAltName: host "login.salesforce.com" matched cert's "login.salesforce.com"
*  issuer: C=US; O=DigiCert Inc; CN=DigiCert SHA2 Secure Server CA
*  SSL certificate verify ok.
> POST /services/oauth2/token HTTP/1.1
> Host: login.salesforce.com
> User-Agent: curl/7.65.3
> Accept: */*
> 'X-PrettyPrint:1'
> Content-Length: 293
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 293 out of 293 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Date: Tue, 20 Aug 2019 01:17:29 GMT
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< Public-Key-Pins-Report-Only: pin-sha256="9n0izTnSRF+W4W4JTq51avSXkWhQB8duS2bxVLfzXsY="; pin-sha256="5kJvNEMw0KjrCAu7eXY5HZdvyCS13BbA0VJG1RSP91w="; pin-sha256="njN4rRG+22dNXAi+yb8e3UMypgzPUPHlv4+foULwl1g="; max-age=86400; includeSubDomains; report-uri="https://a.forcesslreports.com/hpkp-report/nullm";
< Expect-CT: max-age=86400; report-uri="https://a.forcesslreports.com/Expect-CT-report/nullm";
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache,must-revalidate,max-age=0,no-store,private
< Set-Cookie: BrowserId=kxBGP1wCQXOEUcyoQKRFoQ;Path=/;Domain=.salesforce.com;Expires=Sat, 19-Oct-2019 01:17:29 GMT;Max-Age=5184000
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< X-ReadOnlyMode: false
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
<
{"error":"invalid_grant","error_description":"authentication failure"}* Connection #0 to host login.salesforce.com left intact


I have tried all the suggestions I have found online including the following to no avail:
  1. Setting the connected app to have full access
  2. Setting IP restrictions to relaxed
  3. Setting users to authenticate themselves
  4. Enabling the connected app on the System Administrator profile (which is the profile I'm using)
  5. Ensuring the profile also has 'API Enabled' setting enabled.
  6. Setting Login IP ranges for profile to all possible values.
  7. Ensuring there is no space or character between password and security token
I have been unsuccessful thus far. Could someone please help me to fix this problem? Thanks in advance.