Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8386177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:51:49+00:00 2026-06-09T17:51:49+00:00

I am currently developing a WebSocket server in Python but I am not able

  • 0

I am currently developing a WebSocket server in Python but I am not able to calculate the Sec-WebSocket-Accept apparently, which is not very difficult normally.
Here is my function to calculate this (written in Python) :

def get_accept_websocket_key(self, key):
    magic_string = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11'
    key += magic_string
    return base64.b64encode(hashlib.sha1(key).hexdigest())

All my results seems to be good but I always have in the javascript console :

Error during WebSocket handshake: Sec-WebSocket-Accept mismatch

Have you any solution?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:51:51+00:00Added an answer on June 9, 2026 at 5:51 pm

    The working example.
    Lookup at code with “Sec-WebSocket-Protocol”

    from base64 import b64encode, b64decode
    from hashlib import sha1
    
    def sendHeaers(self, connect)
        data = ["HTTP/1.1 101 Switching Protocols",
                "\r\nUpgrade: websocket",
                "\r\nConnection: Upgrade"]
    
        if 'Sec-WebSocket-Protocol' in self.httpHeader:
            data.append("\r\nSec-WebSocket-Protocol: webserver")
    
        if 'Sec-WebSocket-Key' in self.httpHeader:
            sha1f = sha1()
            sha1f.update(self.httpHeader['Sec-WebSocket-Key'] + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
            ticket = b64encode(sha1f.digest())
            data.append("\r\nSec-WebSocket-Accept: " + ticket)
    
        data.append("\r\n\r\n")
        connect.send( "".join(data) )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently developing an application and I need to be able when pressing
I currently developing a multi-language interface for a Django project. But when I started
I'm currently developing an application which needs a lot of system and process information,
Hi I'm currently developing an app that requires a very large download (100-200MB) on
Am currently developing an iPad app which uses a UIScrollView. The UIScrollView is populated
I'm currently developing a Django site in which users can have multiple 'accounts', so
Im currently developing a chat client for the iphone. Server-side there is a node.js
im currently developing an app which plays the steam audio using MediaPlayer class. And
We are currently developing a server whereby a client requests interest in changes to
I'm currently developing for a handheld device running Windows XP Professional (not Tablet PC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.