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

who know how to add proxy and request #3262

Open
gordon7824 opened this issue May 2, 2024 · 4 comments
Open

who know how to add proxy and request #3262

gordon7824 opened this issue May 2, 2024 · 4 comments

Comments

@gordon7824
Copy link

No description provided.

@benhacka
Copy link

benhacka commented May 2, 2024

smth like this one for rest requests

@classmethod
def sendRequest(
    cls, host, port, path, headers, params, reqType="GET", preview=False
):
    proxy_uri = "http://username:password@host:port"

    logger.debug(
        "sendRequest(host=%s, port=%s, path=%s, headers=%s, params=%s, reqType=%s, preview=%s)"
        % (host, port, path, headers, params, reqType, preview)
    )

    params = cls.urlencodeParams(params)

    path = path + "?" + params if reqType == "GET" and params else path

    if not preview:
        logger.debug("Opening connection to %s" % host)
        url = urlparse(proxy_uri)
        conn = httplib.HTTPSConnection(url.hostname, url.port)

        if url.username and url.password:
            auth = "%s:%s" % (url.username, url.password)
            headers[
                "Proxy-Authorization"
            ] = "Basic " + base64.b64encode(auth.encode()).decode("ascii")
        conn.set_tunnel(host, port, headers)
    else:
        logger.debug(
            "Should open connection to %s, but this is a preview" % host
        )
        conn = None

    if not preview:
        logger.debug("Sending %s request to %s" % (reqType, path))
        conn.request(reqType, path, params, headers)
    else:
        logger.debug(
            "Should send %s request to %s, but this is a preview"
            % (reqType, path)
        )
        return None

    response = conn.getresponse()
    return response

@gordon7824
Copy link
Author

gordon7824 commented May 2, 2024 via email

@benhacka
Copy link

benhacka commented May 2, 2024

D 2024-05-02 22:35:24,280 yowsup.common.http.warequest - Opening connection to v.whatsapp.net Traceback (most recent call last): File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup-cli", line 722, in if not parser.process(): ^^^^^^^^^^^^^^^^ File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup-cli", line 387, in process self.handleRequestCode(self.args["requestcode"], config) File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup-cli", line 399, in handleRequestCode result = codeReq.send(encrypt=self._encrypt, preview=self._preview) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup\registration\coderequest.py", line 46, in send res = super(WACodeRequest, self).send(parser, encrypt=encrypt, preview=preview) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup\common\http\warequest.py", line 150, in send return self.sendGetRequest(parser, encrypt, preview=preview) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup\common\http\warequest.py", line 222, in sendGetRequest self.response = WARequest.sendRequest(host, port, path, headers, params, "GET", preview=preview) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup\common\http\warequest.py", line 311, in sendRequest url = urlparse(proxy_uri) ^^^^^^^^ NameError: name 'urlparse' is not defined

On Thu, 2 May 2024 at 21:54, benhacka @.> wrote: smth like this one for code request @classmethoddef sendRequest( cls, host, port, path, headers, params, reqType="GET", preview=False ): proxy_uri = @.:port" logger.debug( "sendRequest(host=%s, port=%s, path=%s, headers=%s, params=%s, reqType=%s, preview=%s)" % (host, port, path, headers, params, reqType, preview) ) params = cls.urlencodeParams(params) path = path + "?" + params if reqType == "GET" and params else path if not preview: logger.debug("Opening connection to %s" % host) url = urlparse(proxy_uri) conn = httplib.HTTPSConnection(url.hostname, url.port) if url.username and url.password: auth = "%s:%s" % (url.username, url.password) headers[ "Proxy-Authorization" ] = "Basic " + base64.b64encode(auth.encode()).decode("ascii") conn.set_tunnel(host, port, headers) else: logger.debug( "Should open connection to %s, but this is a preview" % host ) conn = None if not preview: logger.debug("Sending %s request to %s" % (reqType, path)) conn.request(reqType, path, params, headers) else: logger.debug( "Should send %s request to %s, but this is a preview" % (reqType, path) ) return None response = conn.getresponse() return response — Reply to this email directly, view it on GitHub <#3262 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIVADAQZWWWXNPTLT5OYO2TZAJAR7AVCNFSM6AAAAABHCYWMZCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJQGU3DAOBUGY . You are receiving this because you authored the thread.Message ID: @.***>

try:
    # py3
    from urllib.parse import urlparse
except ImportError:
    # py2
    from urlparse import urlparse

@gordon7824
Copy link
Author

Traceback (most recent call last):
File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup-cli", line 722, in
if not parser.process():
^^^^^^^^^^^^^^^^
File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup-cli", line 387, in process
self.handleRequestCode(self.args["requestcode"], config)
File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup-cli", line 399, in handleRequestCode
result = codeReq.send(encrypt=self._encrypt, preview=self._preview)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup\registration\coderequest.py", line 46, in send
res = super(WACodeRequest, self).send(parser, encrypt=encrypt, preview=preview)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup\common\http\warequest.py", line 150, in send
return self.sendGetRequest(parser, encrypt, preview=preview)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\60113\Desktop\自动注册WA\个人版\yowsup\common\http\warequest.py", line 228, in sendGetRequest
if not self.response.status == WARequest.OK:
^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'status'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants