zerodha / cppkiteconnect

C++ Kite Connect API library / SDK
Other
48 stars 22 forks source link

Failed to send http/https request (enum code: 10) #13

Closed ghost closed 3 years ago

ghost commented 3 years ago

$ ./example1 Running.. Login URL: https://kite.zerodha.com/connect/login?v=3&api_key=uuuuuuuuuu Login with this URL and obtain the request token. Enter obtained request token: BHUBjVL4o5w5F4kZXfUU5D6q327JqmnG Failed to send http/https request (enum code: 10)

when trying to run example1 after successfully building it with the make it generates Failed to sent http/https request during runtime. I couldn't figure it out why is it happening and how to fix it.

I would be thankful if this problem is fixed.

Thanks in advance : )

example1.cpp

/*

include

include

include "kitepp.hpp"

namespace kc = kiteconnect;

int main() {

std::cout << "Running..\n";

try {

    //kc::kite Kite(std::getenv("KITE_API_KEY"));
     kc::kite Kite("please_enter_api_key");

    std::cout << "Login URL: " << Kite.loginURL() << "\nLogin with this URL and obtain the request token.\n";

    std::string apiSecret;
    std::string reqToken;

    std::cout << "Enter obtained request token: ";
    std::cin >> reqToken;

    // std::cout << "Enter API secret: ";
    // std::cin >> apiSecret;
    //apiSecret = std::getenv("KITE_API_SECRET");
apiSecret="please_enter_apisecret";

    std::string accessToken = Kite.generateSession(reqToken, apiSecret).tokens.accessToken;
    std::cout << "access token is " << accessToken << "\n";

    Kite.setAccessToken(accessToken);

    kc::userProfile profile = Kite.profile();
    std::cout << "email is :" << profile.email << "\n";
    std::cout << "Order types are: \n";
    for (const std::string& type : profile.orderTypes) { std::cout << type << ", "; };

    // clang-format off

} catch (kc::kiteppException& e) {

std::cerr << e.what() << ", " << e.code() << ", " << e.message() << "\n";

} catch (kc::libException& e) {

 std::cerr << e.what() << "\n";

} catch (std::exception& e) {

std::cerr << e.what() << std::endl;

}; // clang-format on

return 0;

};

bhumitattarde commented 3 years ago

Hi, I couldn't reproduce this on my end. IIRC, that error code represents SSL error. Have you linked openssl development package? What OS+distro/version are you on? Did you run the tests? Could you share the output?

ghost commented 3 years ago

@bhumitattarde sorry for replying so late .

The OS I am using $ uname -a Linux an 5.10.0-kali3-amd64 #1 SMP Debian 5.10.13-1kali1 (2021-02-08) x86_64 GNU/Linux

the makefile that I am using to generate the example1 which is an executable

CMAKE generated file: DO NOT EDIT!

Generated by "Unix Makefiles" Generator, CMake Version 3.18

Default target executed when no arguments are given to make.

default_target: all

.PHONY : default_target

Allow only one "make -f Makefile2" at a time, but pass parallelism.

.NOTPARALLEL:

=============================================================================

Special targets provided by cmake.

Disable implicit rules so canonical targets will work.

.SUFFIXES:

Disable VCS-based implicit rules.

% : %,v

Disable VCS-based implicit rules.

% : RCS/%

Disable VCS-based implicit rules.

% : RCS/%,v

Disable VCS-based implicit rules.

% : SCCS/s.%

Disable VCS-based implicit rules.

% : s.%

.SUFFIXES: .hpux_make_needs_suffix_list

Command-line flag to silence nested $(MAKE).

$(VERBOSE)MAKESILENT = -s

Suppress display of executed commands.

$(VERBOSE).SILENT:

A target that is always out of date.

cmake_force:

.PHONY : cmake_force

=============================================================================

Set environment variables for the build.

The shell in which to execute make rules.

SHELL = /bin/sh

The CMake executable.

CMAKE_COMMAND = /usr/bin/cmake

The command to remove a file.

RM = /usr/bin/cmake -E rm -f

Escaping for special characters.

EQUALS = =

The top-level source directory on which CMake was run.

CMAKE_SOURCE_DIR = /home/devpar/Documents/cppkiteconnect/rema2

The top-level build directory on which CMake was run.

CMAKE_BINARY_DIR = /home/devpar/Documents/cppkiteconnect/rema2

=============================================================================

Targets provided globally by CMake.

Special rule for the target rebuild_cache

rebuild_cache: @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." /usr/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) .PHONY : rebuild_cache

Special rule for the target rebuild_cache

rebuild_cache/fast: rebuild_cache

.PHONY : rebuild_cache/fast

Special rule for the target edit_cache

edit_cache: @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." /usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available. .PHONY : edit_cache

Special rule for the target edit_cache

edit_cache/fast: edit_cache

.PHONY : edit_cache/fast

The main all target

all: cmake_check_build_system $(CMAKE_COMMAND) -E cmake_progress_start /home/devpar/Documents/cppkiteconnect/rema2/CMakeFiles /home/devpar/Documents/cppkiteconnect/rema2//CMakeFiles/progress.marks $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all $(CMAKE_COMMAND) -E cmake_progress_start /home/devpar/Documents/cppkiteconnect/rema2/CMakeFiles 0 .PHONY : all

The main clean target

clean: $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean .PHONY : clean

The main clean target

clean/fast: clean

.PHONY : clean/fast

Prepare targets for installation.

preinstall: all $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall .PHONY : preinstall

Prepare targets for installation.

preinstall/fast: $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall .PHONY : preinstall/fast

clear depends

depend: $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 .PHONY : depend

=============================================================================

Target rules for targets named example1

Build rule for target.

example1: cmake_check_build_system $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 example1 .PHONY : example1

fast build rule for target.

example1/fast: $(MAKE) $(MAKESILENT) -f CMakeFiles/example1.dir/build.make CMakeFiles/example1.dir/build .PHONY : example1/fast

target to build an object file

example1.o: $(MAKE) $(MAKESILENT) -f CMakeFiles/example1.dir/build.make CMakeFiles/example1.dir/example1.o .PHONY : example1.o

target to preprocess a source file

example1.i: $(MAKE) $(MAKESILENT) -f CMakeFiles/example1.dir/build.make CMakeFiles/example1.dir/example1.i .PHONY : example1.i

target to generate assembly for a file

example1.s: $(MAKE) $(MAKESILENT) -f CMakeFiles/example1.dir/build.make CMakeFiles/example1.dir/example1.s .PHONY : example1.s

Help Target

help: @echo "The following are some of the valid targets for this Makefile:" @echo "... all (the default if no target is provided)" @echo "... clean" @echo "... depend" @echo "... edit_cache" @echo "... rebuild_cache" @echo "... example1" @echo "... example1.o" @echo "... example1.i" @echo "... example1.s" .PHONY : help

=============================================================================

Special targets to cleanup operation of make.

Special rule to run CMake to check the build system integrity.

No rule that depends on this can have commands that come from listfiles

because they might be regenerated.

cmake_check_build_system: $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 .PHONY : cmake_check_build_system

My working directory

CMakeCache.txt CMakeFiles cmake_install.cmake CMakeLists.txt cpp-httplib example1 example1.cpp fmt kitepp kitepp.hpp Makefile PicoSHA2 rapidjson

I have not run the tests.

Output when I run └─$ ./example1
Running.. Login URL: https://kite.zerodha.com/connect/login?v=3&api_key=please_enter_ur_key Login with this URL and obtain the request token. Enter obtained request token: the request token Failed to send http/https request (enum code: 10)

bhumitattarde commented 3 years ago

Try running tests.

I see you are on Kali. Kali usually has very different firewall settings than most other distros designed for daily use. I'd suggest you to double check your firewall and update the packages to the latest.

If you have Ubuntu (Debian based like Kali)/Fedora, could you try on there and report back? This will help us ascertain if the problem is with cppkiteconnect or with your OS settings.

Additionally, make sure your date and time settings are right. Wrong OS datetimes are known to cause SSL verification errors.

ghost commented 3 years ago

thanks @bhumitattarde for you support I will try to solve the problem in Kali If still I fail then I will use cppkiteconnect on Ubuntu.

bhumitattarde commented 3 years ago

Closing this, open again if you face the same issue on Ubuntu.Fedora.

kushsharma2910 commented 3 years ago

Facing the same issue in ubuntu. Were you able to solve this?

bhumitattarde commented 3 years ago

@khushsharma2910 are you on kali too?

kushsharma2910 commented 3 years ago

I am using MacOS.

bhumitattarde commented 3 years ago

Did you run the tests?

kushsharma2910 commented 3 years ago

kushsharma@Kushs-MacBook-Air build % ./kiteTest Running main() from /Users/kushsharma/Desktop/Work/cppkiteconnect/deps/deps/googletest-release-1.10.0/googletest/src/gtest_main.cc [==========] Running 40 tests from 1 test suite. [----------] Global test environment set-up. [----------] 40 tests from kiteTest [ RUN ] kiteTest.constructorTest [ OK ] kiteTest.constructorTest (1 ms) [ RUN ] kiteTest.loginURLTest [ OK ] kiteTest.loginURLTest (0 ms) [ RUN ] kiteTest.generateSessionTest [ OK ] kiteTest.generateSessionTest (2 ms) [ RUN ] kiteTest.invalidateSessionTest [ OK ] kiteTest.invalidateSessionTest (0 ms) [ RUN ] kiteTest.profile [ OK ] kiteTest.profile (2 ms) [ RUN ] kiteTest.getMarginsTest1 [ OK ] kiteTest.getMarginsTest1 (2 ms) [ RUN ] kiteTest.getMarginsTest2 [ OK ] kiteTest.getMarginsTest2 (2 ms) [ RUN ] kiteTest.placeOrderTest [ OK ] kiteTest.placeOrderTest (2 ms) [ RUN ] kiteTest.modifyOrderTest [ OK ] kiteTest.modifyOrderTest (0 ms) [ RUN ] kiteTest.cancelOrderTest [ OK ] kiteTest.cancelOrderTest (0 ms) [ RUN ] kiteTest.exitOrderTest [ OK ] kiteTest.exitOrderTest (1 ms) [ RUN ] kiteTest.ordersTest [ OK ] kiteTest.ordersTest (3 ms) [ RUN ] kiteTest.orderHistoryTest [ OK ] kiteTest.orderHistoryTest (2 ms) [ RUN ] kiteTest.tradesTest [ OK ] kiteTest.tradesTest (2 ms) [ RUN ] kiteTest.orderTradesTest [ OK ] kiteTest.orderTradesTest (1 ms) [ RUN ] kiteTest.placeGTTTest [ OK ] kiteTest.placeGTTTest (1 ms) [ RUN ] kiteTest.getGTTsTest [ OK ] kiteTest.getGTTsTest (2 ms) [ RUN ] kiteTest.getGTTTest [ OK ] kiteTest.getGTTTest (3 ms) [ RUN ] kiteTest.modifyGTTTest [ OK ] kiteTest.modifyGTTTest (4 ms) [ RUN ] kiteTest.deleteGTTTest [ OK ] kiteTest.deleteGTTTest (1 ms) [ RUN ] kiteTest.holdingsTest [ OK ] kiteTest.holdingsTest (3 ms) [ RUN ] kiteTest.getPositionsTest [ OK ] kiteTest.getPositionsTest (3 ms) [ RUN ] kiteTest.convertPositionTest [ OK ] kiteTest.convertPositionTest (2 ms) [ RUN ] kiteTest.getQuoteTest [ OK ] kiteTest.getQuoteTest (3 ms) [ RUN ] kiteTest.getOHLCTest [ OK ] kiteTest.getOHLCTest (1 ms) [ RUN ] kiteTest.getLTPTest [ OK ] kiteTest.getLTPTest (2 ms) [ RUN ] kiteTest.getHistoricalDataTest [ OK ] kiteTest.getHistoricalDataTest (2 ms) [ RUN ] kiteTest.placeMFOrderTest [ OK ] kiteTest.placeMFOrderTest (2 ms) [ RUN ] kiteTest.cancelMFOrderTest [ OK ] kiteTest.cancelMFOrderTest (2 ms) [ RUN ] kiteTest.getMFOrdersTest [ OK ] kiteTest.getMFOrdersTest (2 ms) [ RUN ] kiteTest.getMFOrderTest [ OK ] kiteTest.getMFOrderTest (2 ms) [ RUN ] kiteTest.getMFHoldingsTest [ OK ] kiteTest.getMFHoldingsTest (2 ms) [ RUN ] kiteTest.placeMFSIPTest [ OK ] kiteTest.placeMFSIPTest (0 ms) [ RUN ] kiteTest.modifyMFSIPTest [ OK ] kiteTest.modifyMFSIPTest (0 ms) [ RUN ] kiteTest.cancelMFSIPTest [ OK ] kiteTest.cancelMFSIPTest (1 ms) [ RUN ] kiteTest.getSIPsTest [ OK ] kiteTest.getSIPsTest (1 ms) [ RUN ] kiteTest.getSIPTest [ OK ] kiteTest.getSIPTest (2 ms) [ RUN ] kiteTest.getOrderMarginsTest [ OK ] kiteTest.getOrderMarginsTest (2 ms) [ RUN ] kiteTest.getInstrumentsTest [ OK ] kiteTest.getInstrumentsTest (3 ms) [ RUN ] kiteTest.getMFInstrumentsTest [ OK ] kiteTest.getMFInstrumentsTest (3 ms) [----------] 40 tests from kiteTest (71 ms total)

[----------] Global test environment tear-down [==========] 40 tests from 1 test suite ran. (71 ms total) [ PASSED ] 40 tests. kushsharma@Kushs-MacBook-Air build % ls CMakeCache.txt Makefile cmake_install.cmake kiteTest CMakeFiles RJTest kWSTest kushsharma@Kushs-MacBook-Air build % ./RJTest Running main() from /Users/kushsharma/Desktop/Work/cppkiteconnect/deps/deps/googletest-release-1.10.0/googletest/src/gtest_main.cc [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from RJTest [ RUN ] RJTest.parseTest [ OK ] RJTest.parseTest (0 ms) [----------] 1 test from RJTest (0 ms total)

[----------] Global test environment tear-down [==========] 1 test from 1 test suite ran. (0 ms total) [ PASSED ] 1 test. kushsharma@Kushs-MacBook-Air build % ./kWSTest Running main() from /Users/kushsharma/Desktop/Work/cppkiteconnect/deps/deps/googletest-release-1.10.0/googletest/src/gtest_main.cc [==========] Running 1 test from 1 test suite. [----------] Global test environment set-up. [----------] 1 test from kWSTest [ RUN ] kWSTest.binaryParsingTest [ OK ] kWSTest.binaryParsingTest (3 ms) [----------] 1 test from kWSTest (3 ms total)

[----------] Global test environment tear-down [==========] 1 test from 1 test suite ran. (3 ms total) [ PASSED ] 1 test.

bhumitattarde commented 3 years ago

@kushsharma2910 Next time use make && make test ARGS='-v'.

Facing the same issue in ubuntu. Were you able to solve this? I am using MacOS.

I'm guessing you wrote Ubuntu accidentally?

I cannot reproduce this on my Ubuntu VM/Fedora machine. I also don't have access to a MacOS box to test this out. Have you checked your firewall settings? OS datetime? Can you try sending a HTTPS request using cpp-httplib? Use one of the examples in linked repository.

kushsharma2910 commented 3 years ago

Tried it on ubuntu also, on first installation, it showed the same error but on reinstalling everything resolved it on ubuntu but I cannot resolve the same for macOS.

While development, have you tried to run it on macOS ? Maybe there is some installation problem. I have made sure it is not an issue of firewall.

bhumitattarde commented 3 years ago

It actually hasn't been tested on MacOS yet but it shouldn't be a problem, not one related to SSL definitely. I would have debugged this myself but I like I said, I don't have a mac box available. Also, What is your OpenSSL version?

@knadh @rhnvrm Would it be possible for you guys to test/debug this on MacOS?

rhnvrm commented 3 years ago

@ajinasokan could you help with this?

Apart from this, maybe we can consider adding github actions to this repo (ref: https://github.com/zerodha/cppkiteconnect/pull/12#issuecomment-789710926 with gitlab build pipeline). I recently added support for github actions on gokiteconnect, you can refer the matrix implementation here: https://github.com/zerodha/gokiteconnect/blob/master/.github/workflows/go-test.yml#L17

ajinasokan commented 3 years ago

@bhumitattarde I was trying to build in macOS. The included httplib doesn't seem to compile. It looks like a C++ version(c++11) issue and the code in yhirose/cpp-httplib also seem to different from the one included. And I'm able to compile that. I believe the one you embedded is not compatible with 11.

To setup I had to install uWS:

cd deps
cmake .

cd deps
tar -xvf uWebSocketsv-0.14.8.tar.gz
cd uWebSockets-0.14.8
make
make installDarwin

Install openssl, googletest and doxygen:

brew install openssl
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
brew install googletest
brew install doxygen

And then I encountered the C++11 errors.

bhumitattarde commented 3 years ago

@rhnvrm I'll look into it.

bhumitattarde commented 3 years ago

@ajinasokan Thank you for testing this. I'll update cpp-httplib. To confirm, you tested using cpp-httplib master, that is commit 676f1b5, correct?

ajinasokan commented 3 years ago

Yes it was master latest commit

bhumitattarde commented 3 years ago

@kushsharma2910 Does #22 solve the issue for you?

kushsharma2910 commented 2 years ago

@kushsharma2910 Does #22 solve the issue for you?

Hi @bhumitattarde , sorry for replying so late. This issue had something to do with the openssl version that was getting linked. I reinstalled openssl and:

For compilers to find openssl@3 I had to set: export LDFLAGS="-L/usr/local/opt/openssl@3/lib" export CPPFLAGS="-I/usr/local/opt/openssl@3/include"

On following the above steps, the issue got resolved. Thanks a lot for your support!