wyyerd / stripe-rs

Rust API bindings for the Stripe HTTP API.
Apache License 2.0
219 stars 88 forks source link

How to use stripe-rs in actix context #191

Closed arn-the-long-beard closed 2 years ago

arn-the-long-beard commented 2 years ago

Hello guys :smile:

Thank you so much for your crate :wink: !! Now, I saw there is already an issue regarding actix-web but this one seemed a bit different so i decided to post the issue.

I have 2 small issues.

1 - Here is what I get when I try to use the crate in my actix web server :

thread 'actix-rt:worker:0' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime',

I also tried this solution right here since the error message was similar but I get the same error : https://stackoverflow.com/questions/66119865/how-do-i-use-actix-web-3-and-rusoto-0-46-together

I saw your discussed about having documentation or doing something else about actix.

2 - I cannot write like in the example the following

let client = stripe::r#async::Client::new(secret_key);

For some reason rust cannot find Client from r#async

I am using the following :

actix-web = "3.3.2" 
actix-rt = "1.1.1"

I cannot upgrade to actix-web 4 right now because I would have so much things to change.

Is there a way I can help you guys on how we can solve this ?

seanpianka commented 2 years ago

This is an issue with compatibility between tokio 0.2 vs 1.0, see the dependencies of actix-rt = "1.1.1". Unfortunately, the way to fix this is to update actix-rt to 2.x.

arn-the-long-beard commented 2 years ago

Hello, so it seems I do have to move to the actix-web 4 beta. Okay, i ll give it a try and I come back to see if it solves the issue.

arn-the-long-beard commented 2 years ago

Well @seanpianka , I did the updates :smile: .

Here is my new dependencies


actix-web = { version = "4.0.0-beta.5", features = ["rustls"] }
actix-web-grants = "3.0.0-beta.2"
actix-service = "2.0.0"
actix-cors="0.6.0-beta.2"
actix-rt = "2.2.0"
actix-identity = "0.4.0-beta.2"
actix-files = "0.6.0-beta.6"

I get the same error

thread 'main' panicked at 'not currently running on a Tokio 0.2.x runtime.

I am missing something somewhere ?

EDIT: I might have found why, I am fixing it. EDIT: Everything is fixed. I had to update my database driver also to use the right version for tokio so now everything is fine.

Thank you so much @seanpianka , now I will use the api :smile: