Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to close the SSL connection correctly? #52

Open
Steinadler177 opened this issue Mar 22, 2024 · 2 comments
Open

How to close the SSL connection correctly? #52

Steinadler177 opened this issue Mar 22, 2024 · 2 comments
Labels
bug Something isn't working question Further information is requested

Comments

@Steinadler177
Copy link

Steinadler177 commented Mar 22, 2024

Is there a method that I can close the SSL connection which is build by Subgrounds? I checked the API document which doesn't have a similar content.

I tried to close it with contextlib, but it also can't solve this problem.

# Import the Subgrounds library
    
from subgrounds import Subgrounds
from contextlib import closing
import os


def another_function():
    

    # load_dotenv()
    graph_api_key = '<REDACTED>'
    # Create a new Subgrounds object
    with closing(Subgrounds()) as sg:


        # Load the Uniswap v3 subgraph using a specific API endpoint
        uni = sg.load_subgraph(
            f'https://gateway.thegraph.com/api/{graph_api_key}/subgraphs/id/ELUcwgpm14LKPLrBRuVvPvNKHQ9HvwmtKgKSH6123cr7')
        # <REDACTED>
        # Query the financialsDailySnapshots endpoint with a specified order, limit, and filter criteria
        latest_snapshots = uni.Query.financialsDailySnapshots(
            orderBy=uni.FinancialsDailySnapshot.timestamp,
            orderDirection='desc',
            first=1,
        )

        # Convert the query results to a Pandas dataframe and extract the first row
        res = sg.query_df(latest_snapshots).squeeze()
        pass
    print("Another function")


another_function()

which would give me two error message:

AttributeError: 'Subgrounds' object has no attribute 'close'
I can't close it like this.

sys:1: ResourceWarning: unclosed <ssl.SSLSocket fd=1588, family=23, type=1, proto=0, laddr=('local_address'), raddr=('remote_address')>

That's the real problem. When the program end, PY just simply terminate everything and trigger this error. I can read data from this, but how to safely close the connection?

@Steinadler177 Steinadler177 added the enhancement New feature or request label Mar 22, 2024
@0xMochan 0xMochan added question Further information is requested bug Something isn't working and removed enhancement New feature or request labels Mar 28, 2024
@0xMochan
Copy link
Collaborator

There's no need to utilize contextlib.closing for this purpose, it won't add anything extra to the with Subgrounds() as sg behavior.

Unfortuntely, this SSL socket warning has crept up in a recent update to subgrounds and I haven't fully figured out where it came from. It can safely be ignored and won't affect anything and if the messages get in the way, you can use the warnings module to ignore them from the output:

import warnings                                                           
                                                                              
warnings.filterwarnings('ignore', category=ResourceWarning)

The intended usage should be as follows:

with Subgrounds() as sg:
    sg.load_subgraph("<url here>")
    data = sg.query_df([...])

You can learn more about query grouping in our docs! Let me know if you have further questions!

@Steinadler177
Copy link
Author

Understood. I'll try to import this warn filter for this module. Thank you very much! Please change the issue status on your control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants