René's URL Explorer Experiment


Title: How to keep session alive when using async websockets? · Issue #491 · python/asyncio · GitHub

Open Graph Title: How to keep session alive when using async websockets? · Issue #491 · python/asyncio

X Title: How to keep session alive when using async websockets? · Issue #491 · python/asyncio

Description: I have this code to interact with a websocket api using async and websokets python libraries: #!/usr/bin/env python3 import sys, json import asyncio from websockets import connect class AsyncWebsocket(): async def __aenter__(self): self....

Open Graph Description: I have this code to interact with a websocket api using async and websokets python libraries: #!/usr/bin/env python3 import sys, json import asyncio from websockets import connect class AsyncWebsoc...

X Description: I have this code to interact with a websocket api using async and websokets python libraries: #!/usr/bin/env python3 import sys, json import asyncio from websockets import connect class AsyncWebsoc...

Opengraph URL: https://github.com/python/asyncio/issues/491

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to keep session alive when using async websockets?","articleBody":"I have this code to interact with a websocket api using `async` and `websokets` python libraries:\r\n\r\n```\r\n#!/usr/bin/env python3\r\n\r\nimport sys, json\r\nimport asyncio\r\nfrom websockets import connect\r\n\r\nclass AsyncWebsocket():\r\n    async def __aenter__(self):\r\n        self._conn = connect('wss://ws.myws.com/v2')\r\n        self.websocket = await self._conn.__aenter__()        \r\n        return self\r\n\r\n    async def __aexit__(self, *args, **kwargs):\r\n        await self._conn.__aexit__(*args, **kwargs)\r\n\r\n    async def send(self, message):\r\n        await self.websocket.send(message)\r\n\r\n    async def receive(self):\r\n        return await self.websocket.recv()\r\n\r\nclass mtest():\r\n    def __init__(self, api_token):\r\n        self.aws        = AsyncWebsocket()\r\n        self.loop       = asyncio.get_event_loop()\r\n        self.api_token  = api_token\r\n        \r\n        self.authorize()\r\n\r\n    def authorize(self):\r\n        jdata = self.__async_exec({\r\n                                    'authorize': self.api_token\r\n                                  })\r\n\r\n        try:\r\n            print (jdata['email'])\r\n            ret = True\r\n        except:\r\n            ret = False\r\n\r\n        return ret\r\n\r\n    def sendtest(self):\r\n\r\n        jdata = self.__async_exec({\r\n                                    \"hello\": 1\r\n                                  })\r\n\r\n        print (jdata)\r\n\r\n\r\n    def __async_exec(self, jdata):\r\n        try:\r\n            ret = json.loads(self.loop.run_until_complete(self.__async_send_recieve(jdata)))\r\n        except:\r\n            ret = None\r\n\r\n        return ret\r\n\r\n    async def __async_send_recieve(self, jdata):\r\n        async with self.aws:\r\n            await self.aws.send(json.dumps(jdata))\r\n            return await self.aws.receive()\r\n```\r\n\r\nSo I have the following in main.py:\r\n    \r\n```\r\nfrom webclass import *\r\n\r\na = mtest('12341234')\r\nprint (a.sendtest())\r\n```\r\n\r\nThe problem is that it doesn't preserve the authorized session, so this is the output:\r\n\r\n```\r\nroot@ubupc1:/home/dinocob# python3 test.py \r\nasd@gmail.com\r\n{'error': {'message': 'Please log in.', 'code': 'AuthorizationRequired'}}\r\n```\r\n\r\nAs you see, the login call are working ok, but when calling and sending the `hello` in `sendtest` function, the session is not the same. \r\n\r\n - Where is destroyed the session? \r\n - How could I preserve it (without drastically\r\n   modifying my class structure)?","author":{"url":"https://github.com/mllamazares","@type":"Person","name":"mllamazares"},"datePublished":"2017-02-09T17:18:59.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/491/asyncio/issues/491"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d53302bd-ca2a-0ae5-bc61-06dcfa43609f
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idABAE:3301CD:470A179:5D0CDE5:696D4EF7
html-safe-nonce12f2c697a673b3c9fffc918dce67e415e23a350272911e5c4abfcdbbdacaef7d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQkFFOjMzMDFDRDo0NzBBMTc5OjVEMENERTU6Njk2RDRFRjciLCJ2aXNpdG9yX2lkIjoiMjgwNjI4ODI1MzgwNTQ4MTcxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace5dc6971961bf7af956bffb35a2dd780b7d4d38cecb1d2ddb1bb42385c5b080d
hovercard-subject-tagissue:206570536
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/asyncio/491/issue_layout
twitter:imagehttps://opengraph.githubassets.com/4175da14ebe382244c282fe8dc0e3cd86d0aeadb910cdc99965ab58cf6b240ce/python/asyncio/issues/491
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/4175da14ebe382244c282fe8dc0e3cd86d0aeadb910cdc99965ab58cf6b240ce/python/asyncio/issues/491
og:image:altI have this code to interact with a websocket api using async and websokets python libraries: #!/usr/bin/env python3 import sys, json import asyncio from websockets import connect class AsyncWebsoc...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemllamazares
hostnamegithub.com
expected-hostnamegithub.com
None0944e430045f4fb5f7bd103e0660080acfe593174063212555773ca41c144a14
turbo-cache-controlno-preview
go-importgithub.com/python/asyncio git https://github.com/python/asyncio.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id33739295
octolytics-dimension-repository_nwopython/asyncio
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id33739295
octolytics-dimension-repository_network_root_nwopython/asyncio
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release66b6e773801d28660016072069017cfcc851f54b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/python/asyncio/issues/491#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fasyncio%2Fissues%2F491
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fasyncio%2Fissues%2F491
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fasyncio
Reloadhttps://patch-diff.githubusercontent.com/python/asyncio/issues/491
Reloadhttps://patch-diff.githubusercontent.com/python/asyncio/issues/491
Reloadhttps://patch-diff.githubusercontent.com/python/asyncio/issues/491
python https://patch-diff.githubusercontent.com/python
asynciohttps://patch-diff.githubusercontent.com/python/asyncio
Please reload this pagehttps://patch-diff.githubusercontent.com/python/asyncio/issues/491
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2Fpython%2Fasyncio
Fork 185 https://patch-diff.githubusercontent.com/login?return_to=%2Fpython%2Fasyncio
Star 1.1k https://patch-diff.githubusercontent.com/login?return_to=%2Fpython%2Fasyncio
Code https://patch-diff.githubusercontent.com/python/asyncio
Issues 76 https://patch-diff.githubusercontent.com/python/asyncio/issues
Pull requests 10 https://patch-diff.githubusercontent.com/python/asyncio/pulls
Actions https://patch-diff.githubusercontent.com/python/asyncio/actions
Projects 0 https://patch-diff.githubusercontent.com/python/asyncio/projects
Wiki https://patch-diff.githubusercontent.com/python/asyncio/wiki
Security Uh oh! There was an error while loading. Please reload this page. https://patch-diff.githubusercontent.com/python/asyncio/security
Please reload this pagehttps://patch-diff.githubusercontent.com/python/asyncio/issues/491
Insights https://patch-diff.githubusercontent.com/python/asyncio/pulse
Code https://patch-diff.githubusercontent.com/python/asyncio
Issues https://patch-diff.githubusercontent.com/python/asyncio/issues
Pull requests https://patch-diff.githubusercontent.com/python/asyncio/pulls
Actions https://patch-diff.githubusercontent.com/python/asyncio/actions
Projects https://patch-diff.githubusercontent.com/python/asyncio/projects
Wiki https://patch-diff.githubusercontent.com/python/asyncio/wiki
Security https://patch-diff.githubusercontent.com/python/asyncio/security
Insights https://patch-diff.githubusercontent.com/python/asyncio/pulse
How to keep session alive when using async websockets?https://patch-diff.githubusercontent.com/python/asyncio/issues/491#top
https://github.com/mllamazares
https://github.com/mllamazares
mllamazareshttps://github.com/mllamazares
on Feb 9, 2017https://github.com/python/asyncio/issues/491#issue-206570536
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.