GithubHelp home page GithubHelp logo

btcpayserver / btcpay-python Goto Github PK

View Code? Open in Web Editor NEW
80.0 80.0 27.0 69 KB

Python client for the BTCPay API.

Home Page: https://docs.btcpayserver.org/integrations/customintegration

License: MIT License

Python 100.00%

btcpay-python's People

Contributors

amperture avatar jeffvandrewjr avatar joeblackwaslike avatar nicolasdorier avatar saurabh130 avatar theseatoms avatar vesellov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

btcpay-python's Issues

requests.exceptions.InvalidURL: Failed to parse:

Hello,
i have try to use the library but i have this error: requests.exceptions.InvalidURL: Failed to parse: https//myserver.com/tokens

i have create Access Tokens and i have put in my script pairing code

i use python 3.8.10

and in script i have put:

from btcpay import BTCPayClient

client = BTCPayClient.create_client(host='MYSERVERULR', code="PAIRINGCODE")

JSONDecodeError: Expecting value: line 3 column 1 (char 2)

I am getting error JSONDecodeError: Expecting value: line 3 column 1 (char 2) when trying to create or get an invoices.
The URL I use for the API calls works fine in the browser when creating a new BTCPay client, but gives this error when creating or getting an invoices within the BTCPay client.

Create invoice

Get a list of invoices matching certain parameters

Getting an issue while integrating my project with btcpay

raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='mybtcpay.local', port=443): Max retries exceeded with url: /tokens (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)'),)) 

I am getting this error followed by other traceback error during custom integration while I run this -

client = BTCPayClient.create_client(host='https://btcpay.example.com', code=<pairing-code>)

When generating an invoice for less than 20 cents, client does not return BTC addresses

invoice_response = client.create_invoice({"price": 1.0, "currency": "USD"})

Returns a normal response.

invoice_response = client.create_invoice({"price": .19, "currency": "USD"})

Returns a response without a BTC address (but does include other currencies).

invoice_response = client.create_invoice({"price": .20, "currency": "USD"})

Also returns a normal response.

Client not found error

Hello!

I'm getting issue with any client action:

  1. Generated key
  2. Paired with server
  3. Trying to get_rates() or gen_Invoice(), but getting this error:

Traceback (most recent call last):
File "main.py", line 31, in
client.get_rates()
File "/usr/local/lib/python3.6/site-packages/btcpay/client.py", line 74, in get_rates
return self._signed_get_request('/rates/', params=params)
File "/usr/local/lib/python3.6/site-packages/btcpay/client.py", line 45, in _signed_get_request
r.raise_for_status()
File "/usr/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: %mybtcpayurl%

testnet server not working

hi, i have issue connecting to testnet server.
here is my code
from btcpay import BTCPayClient

client = BTCPayClient.create_client(host='https://testnet.demo.btcpayserver.org', code="sDRbK7H")

invoice_list = client.get_invoices(status='confirmed')
print(invoice_list)
Do i need to have my own server to test it or it works on testnet?. Thanks

Client Error: Not Found for url

When running BTCPayClient.create_client I'm getting the error:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://*******/tokens

I do have a working SSL certificate (checked due to #11 (comment)).

The issue might be the different certificates:

  • BTCPay - Let's encrypt (used this tutorial to deploy)
  • webhook server - AWS Certificate

Both have the same domain, different subdomains.

Is there any way around this or should I somehow make sure they use the same certificate?

Testnet pairing

Hello,

When I set up my own btcpayserver I could pair, but when I run it on testnet (I created a store on testnet.demo.btcpayserver.org/) I get 400 Client Error: Bad Request for url: https://testnet.demo.btcpayserver.org/tokens

The error is on create_client

BTCPayClient.create_client(
                    host=settings.BTCPAY_SERVER,
                    code=settings.BTCPAY_SERVER_TOKEN)

Any ideas why? Is the server up to date?

IndexError in get_rate() method

Hello guys. Thank you for the work you are doing.

Wanted to report a small bug to you. It looks like our BTCPay node is not very stable sometimes or there are some networking issues. For some reason client.get_rate("USD") occasionally may throw an IndexError list index out of range exception.

Based on the info from our Sentry dashboard I do see that get_rates() method returned an empty list and then further, on line 97 it will brake, because it tries to access the first element of the empty list rates = [] : https://github.com/btcpayserver/btcpay-python/blob/master/btcpay/client.py#L97

Not sure if you like to raise another error in that case, but just decided to report it here.

Thanks!

SSL Verification Error

I have deployed BTCPAY on a Digital Ocean server for testing (btc testnet), and everything is working fine so far except for when I try to create a client in python to connect to the server.

I have generated the pairing code in the server dashboard, but each time I try to create the client in python I get the following SSL errors:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 370, in connect
    ssl_context=context)
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 355, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/local/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/usr/local/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/usr/local/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=XXX, port=443): Max retries exceeded with url: /tokens (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/btcpay/client.py", line 134, in pair_client
    data = self._unsigned_request('/tokens', payload)
  File "/usr/local/lib/python3.7/site-packages/btcpay/client.py", line 81, in _unsigned_request
    r = self.s.post(uri, data=payload)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 581, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 668, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 668, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 247, in resolve_redirects
    **adapter_kwargs
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=XXX, port=443): Max retries exceeded with url: /tokens (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))

When I log the nginx container, I can only see on POST request come in for the /token url for each client connection attempt
[30/Jul/2019:13:28:22 +0000] "POST /tokens HTTP/1.1" 301 162 "-" "python-requests/2.22.0"),
though the SSL error (Max retries exceeded with url: /tokens) makes it seem like it was denied because of too many requests

I did have to add a security exception to access my btcpay website so perhaps the cert wasn't configured properly during the docker setup?

Trouble pairing

Here's my test program directly following the README:

import btcpay.crypto
from btcpay import BTCPayClient

URL = "https://test.buidlbootcamp.com"

privkey = btcpay.crypto.generate_privkey()
client = BTCPayClient(
    host=URL, 
    pem=privkey,
)

pairing_code = "SECRET!!!"
tokens = client.pair_client(pairing_code)

print(client.get_rates())

I encounter this exception:

$ python script.py 
Traceback (most recent call last):
  File "script.py", line 13, in <module>
    tokens = client.pair_client(pairing_code)
  File "/home/justin/dev/buidl-treasury/venv/lib/python3.7/site-packages/btcpay/client.py", line 97, in pair_client
    data = self._unsigned_request('/tokens', payload)
  File "/home/justin/dev/buidl-treasury/venv/lib/python3.7/site-packages/btcpay/client.py", line 65, in _unsigned_request
    r.raise_for_status()
  File "/home/justin/dev/buidl-treasury/venv/lib/python3.7/site-packages/requests/models.py", line 939, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://test.buidlbootcamp.com/tokens

This server is on testnet FWIW

Retrieving Transaction ID from an invoice

Once an invoice is paid/completed/confirmed I need to access the transaction id using the client. It doesn't seem available based on the json response. Is this possible to retrieve or do i need to write my own code to pull it from elsewhere

Error 400 on get_rates

I have my client working with creating invoices. However, when I try to call get_rates(), I get
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://testnet.demo.btcpayserver.org/rates/?cryptoCode=BTC&token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

It's the same client, so I'm thinking this might be a bug?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.