Getting {error,connect_timeout} message while using Hackney - erlang

i am using Hackney's erlang rest client. I followed the steps provided in README.md but I am getting the following error:
17> Method = get.
get
18> URL = <<"www.google.com">>.
<<"www.google.com">>
19> Headers = [].
[]
20> Payload = <<>>.
<<>>
21> Options = [].
[]
22>Test = hackney:request(Method, URL,Headers,Payload,Options).
{error,connect_timeout}
I used the same url using curl and wget and both are working. Is there any issue with erlang ssl or issue with tls? I have edited the question for better understanding
EDIT 1 (using curl -vv google.com)
curl -vv google.com
* About to connect() to proxy <<ip>> port 8080 (#0)
* Trying <<ip>>... connected
* Connected to <<ip>> (<<ip>>) port 8080 (#0)
* Proxy auth using Basic with user '<<user>>'
> GET http://google.com HTTP/1.1
> Proxy-Authorization: <<proxy authorization>>
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: google.com
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1.1 301 Moved Permanently
< Location: http://www.google.com/
< Content-Type: text/html; charset=UTF-8
< Date: Tue, 07 Jun 2016 03:49:43 GMT
< Expires: Thu, 07 Jul 2016 03:49:43 GMT
< Cache-Control: public, max-age=2592000
< Server: gws
< Content-Length: 219
< X-XSS-Protection: 1; mode=block
< X-Frame-Options: SAMEORIGIN
< Proxy-Connection: Keep-Alive
< Connection: Keep-Alive
< Age: 2223
<
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
here.
</BODY></HTML>
* Connection #0 to host <<ip>> left intact
* Closing connection #0

Hackney do not apply profile proxy settings automatically, so you should take care of proxy settings yourself.
According to the documentation, you should provide the following options:
{proxy, {Host, Port}} %% if http proxy is used
{proxy_auth, {User, Password}}. %% if proxy requires authentication

What do you get when you use the httpc module to do a request via the Erlang shell.
First start inets:
inets:start().
Then try:
{ok, Response} = httpc:request("https://www.google.com").
or
{ok, Response} = httpc:request("http://www.google.com").
If both of these fail to connect, odds are the issue is not hackney related, but rather an issue of Erlang as a whole.

Your error is not an connect_timeout. You are getting an exception of no match of right hand side value because you are missing the = on your last command.
Just change it to
{ok, StatusCode, RespHeaders, ClientRef} = hackney:request(Method,URL,Headers,Payload,Options).

Related

Kong: kong-spec-expose plugin cannot load the documentation(302 permanently moved)

I have hard times configuring this kong-spec-expose plugin.It is supposed to automatically configure the routes with Swagger. After some time I managed to configure it but when i try to access the documentation of a certain route it is always giving me the 302 permanently moved.So i tested it with curl and here I will leave a link for the kong plugin and a screenshot of the request..
https://docs.konghq.com/hub/optum/kong-spec-expose/
* Trying 127.0.0.1:8000...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET /api/employee-controller/profile/user/12/base/specz HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.68.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 302 Moved Temporarily
< Date: Wed, 11 Jan 2023 09:50:38 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Kong-Response-Latency: 409
< Server: kong/2.8.1
Actually I tried configuring the plugin on multiple routes then on service level but nothing seems to work out.. then tried to analyse where this request is redirected but with no results.

Git clone hangs on Receiving objects on MAC OSX 10.12

I am trying to setup Cocoapods on mac osx 10.12, I have tried to execute this command in terminal it hangs on receiving object :-
cd ~/.cocoapods/repos
GIT_TRACE=1; GIT_CURL_VERBOSE=1 git clone http://github.com/CocoaPods/Specs.git master --verbose
Here is the terminal output:-
Cloning into 'master'...
* Couldn't find host github.com in the .netrc file; using defaults
* Trying 192.30.253.112...
* Connected to github.com (192.30.253.112) port 80 (#0)
> GET /CocoaPods/Specs.git/info/refs?service=git-upload-pack HTTP/1.1
Host: github.com
User-Agent: git/2.7.4 (Apple Git-66)
Accept: */*
Accept-Encoding: gzip
Pragma: no-cache
< HTTP/1.1 301 Moved Permanently
< Content-length: 0
< Location: https://github.com/CocoaPods/Specs.git/info/refs?service=git-upload-pack
< Connection: close
<
* Closing connection 0
* Issue another request to this URL: 'https://github.com/CocoaPods/Specs.git/info/refs?service=git-upload-pack'
* Couldn't find host github.com in the .netrc file; using defaults
* Trying 192.30.253.112...
* Connected to github.com (192.30.253.112) port 443 (#1)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: github.com
* Server certificate: DigiCert SHA2 Extended Validation Server CA
* Server certificate: DigiCert High Assurance EV Root CA
> GET /CocoaPods/Specs.git/info/refs?service=git-upload-pack HTTP/1.1
Host: github.com
User-Agent: git/2.7.4 (Apple Git-66)
Accept: */*
Accept-Encoding: gzip
Pragma: no-cache
< HTTP/1.1 200 OK
< Server: GitHub Babel 2.0
< Content-Type: application/x-git-upload-pack-advertisement
< Transfer-Encoding: chunked
< Expires: Fri, 01 Jan 1980 00:00:00 GMT
< Pragma: no-cache
< Cache-Control: no-cache, max-age=0, must-revalidate
< Vary: Accept-Encoding
< X-GitHub-Request-Id: 69EEB048:2D36F:6AF964:57888CD0
< X-Frame-Options: DENY
<
* Connection #1 to host github.com left intact
POST git-upload-pack (305 bytes)
* Couldn't find host github.com in the .netrc file; using defaults
* Found bundle for host github.com: 0x7fc3d750be30
* Re-using existing connection! (#1) with host github.com
* Connected to github.com (192.30.253.112) port 443 (#1)
> POST /CocoaPods/Specs.git/git-upload-pack HTTP/1.1
Host: github.com
User-Agent: git/2.7.4 (Apple Git-66)
Accept-Encoding: gzip
Content-Type: application/x-git-upload-pack-request
Accept: application/x-git-upload-pack-result
Content-Length: 305
* upload completely sent off: 305 out of 305 bytes
< HTTP/1.1 200 OK
< Server: GitHub Babel 2.0
< Content-Type: application/x-git-upload-pack-result
< Transfer-Encoding: chunked
< Expires: Fri, 01 Jan 1980 00:00:00 GMT
< Pragma: no-cache
< Cache-Control: no-cache, max-age=0, must-revalidate
< Vary: Accept-Encoding
< X-GitHub-Request-Id: 69EEB048:2D36F:6AFF66:57888CD9
< X-Frame-Options: DENY
<
remote: Counting objects: 747987, done.
remote: Compressing objects: 100% (17/17), done.
Receiving objects: 1% (10862/747987), 2.16 MiB | 437.00 KiB/s
I have seen others questions about this issue here on SO, unfortunately non of there solutions worked.
Update:-
The terminal showed this error after a while:-
* SSLRead() return error -9806/747987), 2.16 MiB | 437.00 KiB/s
* Closing connection 1
error: RPC failed; curl 56 SSLRead() return error -9806
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed`
See this answer.
VMware on NAT had this problem for me. Changing it to Bridged
(replicate the state) fixed the issue.
I confirm it's a network issue on my side. I executed this command on a Windows 10 machine:-
git clone http://github.com/CocoaPods/Specs.git master
Then copied the master repo to this directory on the MAC OSX machine using the terminal cp command (normal copy using Finder hangs for hours):-
~/.cocoapods/repos/master
Then finally doing pod init then pod install --verbose on my project directory worked like a charm

Getting ERR_INSECURE_RESPONSE error before redirecting to ssl page

I have a Rails app on Heroku using Expedited SSL (in case any of that matters).
Now I have permanent forwarding from example.com to https://www.example.com. Occasionally, and I only noticed it on Chrome, when I request the page http://example.com, I get a ERR_INSECURE_RESPONSE error page, then after few seconds, it takes me to the https://www.example.com page and loads just fine.
I ran the inspector for http insecured warnings in console, but nothing. I tried several times to do curl, and on one occasion I got an error.
Bashar:example bashar$ curl -v http://example.com
* Rebuilt URL to: http://example.com/
* Hostname was NOT found in DNS cache
* Trying xx.xx.xx.xx...
* Connected to example.com (xx.xx.xx.xx) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.0
> Host: example.com
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer
Bashar:example bashar$ curl -v http://example.com
* Rebuilt URL to: http://example.com/
* Hostname was NOT found in DNS cache
* Trying xx.xx.xx.xx...
* Connected to example.com (xx.xx.xx.xx) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.0
> Host: example.com
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Cache-Control: max-age=900
< Content-Type: text/html
< Location: https://www.example.com
* Server Microsoft-IIS/7.5 is not blacklisted
< Server: Microsoft-IIS/7.5
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< Date: Tue, 11 Aug 2015 09:15:46 GMT
< Content-Length: 0
< Age: 1
< Connection: keep-alive
<
* Connection #0 to host example.com left intact
I've read several discussions about the topic, but didn't find one exactly like this. Any idea?
I'm not sure if there is another, or better solution. However I found this answer by Brian Heroku SSL on root domain
to move from GoDaddy to DNSimple to do the trick. Can't see the problem anymore, and even better, the site works with and without www, and with http and https. Seems t

iOS payload, but nothing to deliver to (missing device_tokens, tags, segments, or aliases)

I am doing background download for my app but I am getting
iOS payload, but nothing to deliver to (missing device_tokens, tags, segments, or aliases)
when I insert this in terminal:
curl -v -X POST -u "<appKey>:<master key>" -H "Content-type: application/json" -H "Accept:
application/vnd.urbanairship+json; version=3;" --data '{"audience":"all", "device_types" : ["ios"], "notification": {"ios": {"content-available":true, "sound": "default", "badge": 1, "message": "Hi there!", "priority":5}}}' https://go.urbanairship.com/api/push/
I wonder if the curl codes has any format mistakes in it.
Terminal return:
* Hostname was NOT found in DNS cache
* Trying 23.74.208.46...
* Connected to go.urbanairship.com (23.74.208.46) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA
* Server certificate: *.urbanairship.com
* Server certificate: Cybertrust Public SureServer SV CA
* Server certificate: Baltimore CyberTrust Root
* Server auth using Basic with user '<codes>'
> POST /api/push/ HTTP/1.1
> Authorization: Basic <codes>
> User-Agent: curl/7.37.1
> Host: go.urbanairship.com
> Content-type: application/json
> Accept:
> application/vnd.urbanairship+json; version=3;
> Content-Length: 143
>
* upload completely sent off: 143 out of 143 bytes
< HTTP/1.1 400 Bad Request
* Server gunicorn/0.14.5 is not blacklisted
< Server: gunicorn/0.14.5
< Vary: Authorization, Cookie
< X-Frame-Options: SAMEORIGIN
< Content-Type: text/html; charset=utf-8
< Date: Wed, 19 Nov 2014 02:19:02 GMT
< Transfer-Encoding: chunked
< Connection: close
< Connection: Transfer-Encoding
< Set-Cookie: SRV=s0196; path=/
<
* Closing connection 0
iOS payload, but nothing to deliver to (missing device_tokens, tags, segments, or aliases)
First, you should not post your credentials for all to see. This could allow anyone to send notifications to your app users!
Second, the problem appears to be that within your "ios" section you need to specify your audience by means of device tokens, tags, segments, or aliases. These are mechanisms UA gives you to identify which users should receive the notification.

POST request treated as GET in Heroku environment

I have weird case. I have a RoR app, which provides REST API which I'm connecting to from Java application.
I'm developing RoR locally, and deploying it on Heroku environment.
Regardless how (I tried from Java APP, Mozilla REST client, etc.) I try to send POST HTTP request that should be handled by create action in api controller. On localhost - everything is working as expected. On Heroku production env - the POST request is treated as normal GET.
Here are my routes for this resource:
api_v1_items GET /api/v1/items(.:format) api/v1/items#index {:format=>:json}
POST /api/v1/items(.:format) api/v1/items#create {:format=>:json}
api_v1_item GET /api/v1/items/:id(.:format) api/v1/items#show {:format=>:json}
PATCH /api/v1/items/:id(.:format) api/v1/items#update {:format=>:json}
PUT /api/v1/items/:id(.:format) api/v1/items#update {:format=>:json}
DELETE /api/v1/items/:id(.:format) api/v1/items#destroy {:format=>:json}
So I'm trying to do POST request to /api/v1/items passing all necessary parameters.
In localhost the response is correct:
Started POST "/api/v1/items?token=l4XOHrhDApPqTp1u4TxBjQ" for 127.0.0.1 at 2014-05-15 22:11:49 +0200
Processing by Api::V1::ItemsController#create as JSON
Parameters: {"height"=>10.0, "item_name"=>"Super item", "width"=>20.0, etc...
However the same request fired at Heroku its treated as GET:
2014-05-15T20:27:58.137541+00:00 app[web.1]: Started GET "/api/v1/items?token=iEdDkDLiDUlWi0mDbr6XYw" for 89.74.57.51 at 2014-05-15 20:27:58 +0000
2014-05-15T20:27:58.223620+00:00 app[web.1]: Processing by Api::V1::ItemsController#index as JSON
Any idea? Of course both repos are in sync. Checked few times.
This is really weird... maybe some kind of Heroku cache magic?
HTTP/1.1 301 Moved Permanently
301 redirects are not Heroku magic. Your DNS (or possibly your app) is likely forwarding all apex requests (mydomain.com) to the www subdomain.
Using subdomains is preferred:
Heroku Dev Center: Custom Domains
I experienced a similar error when not using a custom domain just because of an easily overlooked error: I was using heroku.com instead of herokuapp.com
wrong:
http://my-app.heroku.com
right:
http://my-app.herokuapp.com
I suspect it's very similar in cause to the issue mentioned in Catsby's answer.
Well, I tried CURL, and it appeared error is silly.
I was posting at http://mydomain.com, where it's routed as GET.
When I fire at http://www.mydomain.com - it works.
Heroku magic.
Below are curl's and results for your reference. Maybe somebody will be able to explain why it works like this...
POST at mydomain.com
curl -v -H "Accept: application/json" -H "Cont"width":20.0,"item_desc":"The super item","std_pack":40,"sku":"A1004","depth":20.0}}' http://mydomain.com/api/v1/items?token=dSWeyKjjtZu0ZSs6b2J-yw
* Adding handle: conn: 0x7fe70b803000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fe70b803000) send_pipe: 1, recv_pipe: 0
* About to connect() to mydomain.com port 80 (#0)
* Trying 78.46.51.229...
* Connected to mydomain.com (78.46.51.229) port 80 (#0)
> POST /api/v1/items?token=dSWeyKjjtZu0ZSs6b2J-yw HTTP/1.1
> User-Agent: curl/7.30.0
> Host: mydomain.com
> Accept: application/json
> Content-type: application/json
> Content-Length: 174
>
* upload completely sent off: 174 out of 174 bytes
< HTTP/1.1 301 Moved Permanently
< Date: Thu, 15 May 2014 21:20:58 GMT
* Server Apache is not blacklisted
< Server: Apache
< Location: http://www.mydomain.com/api/v1/items?token=dSWeyKjjtZu0ZSs6b2J-yw
< Content-Length: 273
< Content-Type: text/html; charset=iso-8859-1
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved here.</p>
</body></html>
* Connection #0 to host mydomain.com left intact
POST at www.mydomain.com
Maciejs-MacBook-Pro:merchbag maciejsimm$ curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"item":{"height":10.0,"item_name":"Super duper item","width":20.0,"item_desc":"The super","std_pack":40,"sku":"A1005","depth":20.0}}' http://www.mydomain.com/api/v1/items?token=dSWeyKjjtZu0ZSs6b2J-yw
* Adding handle: conn: 0x7fc191003000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fc191003000) send_pipe: 1, recv_pipe: 0
* About to connect() to www.mydomain.com port 80 (#0)
* Trying 50.17.185.176...
* Connected to www.mydomain.com (50.17.185.176) port 80 (#0)
> POST /api/v1/items?token=dSWeyKjjtZu0ZSs6b2J-yw HTTP/1.1
> User-Agent: curl/7.30.0
> Host: www.mydomain.com
> Accept: application/json
> Content-type: application/json
> Content-Length: 133
>
* upload completely sent off: 133 out of 133 bytes
< HTTP/1.1 201 Created
< Cache-Control: max-age=0, private, must-revalidate
< Content-Type: application/json; charset=utf-8
< Date: Thu, 15 May 2014 21:24:17 GMT
< Etag: "41231ae0f50a604cd7316a014d19b3f2"
* Server WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08) is not blacklisted
< Server: WEBrick/1.3.1 (Ruby/2.0.0/2014-05-08)
< Set-Cookie: request_method=POST; path=/
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-Request-Id: ba05dd74-bf52-47d5-b8a9-d0516aff5804
< X-Runtime: 0.020289
< X-Ua-Compatible: chrome=1
< X-Xss-Protection: 1; mode=block
< Content-Length: 234
< Connection: keep-alive
<
* Connection #0 to host www.mydomain.com left intact
{"id":15,"partner_id":1,"sku":"A1005","item_name":"Super duper item","item_desc":"The super","std_pack":40,"height":10,"width":20,"depth":20,"image":null,"created_at":"2014-05-15T21:24:17.753Z","updated_at":"2014-05-15T21:24:17.761Z"}
I had this same issue when sending a POST request to heroku using HTTP instead of HTTPS. Every time heroku routed my POST requests as GET requests. Once I updated the url to use HTTPS, my POST requests were routed by heroku as POSTs and not GETs, resolving the issue. The redirection issues mentioned in the previous posts are likely the root cause of the issue I experienced as well.

Resources