Search code examples
proxyerlangelixirhttpoison

How to set a proxy api token as auth on hackney through HTTPoison?


I'm having a problem authenticating on Crawlera service using HTTPoison.

The crawlera's API documentation says I only need the API Token.

i.e. curl -vx proxy.crawlera.com:8010 -U <API key>: http://httpbin.org/ip

So, I'm having problems setting the authentication options on HTTPoison settings.

I'm trying this 3 options:

HTTPoison.get("url", header, hackney: [:insecure], proxy: 'proxy.crawlera.com:8010', proxy_auth: 'api-token') Error -> (FunctionClauseError) no function clause matching in :hackney.do_connect/7

HTTPoison.get("url", header, hackney: [:insecure], proxy: 'proxy.crawlera.com:8010', proxy_auth: {'api-token',''}) Error -> (ArgumentError) argument error :erlang.bit_size([])

HTTPoison.get("url", header, hackney: [:insecure], proxy: 'api-token:@proxy.crawlera.com:8010') Error -> {"X-Crawlera-Error", "bad_proxy_auth"}

If someone knows how to set correctly the parameters I'll appreciate the help.


Solution

    1. The proxy argument should be a tuple of the host and port.
    2. You need to use binaries instead of charlists for the host and both the elements of proxy_auth.

    The following should work:

    proxy: {"proxy.crawlera.com", 8010}, proxy_auth: {"api-token", ""}