Bug 2343976 - python-httpretty fails to build with Python 3.14: AttributeError: 'SSLContext' object has no attribute 'close' & 'sendall'
Summary: python-httpretty fails to build with Python 3.14: AttributeError: 'SSLContext...
Keywords:
Status: MODIFIED
Alias: None
Product: Fedora
Classification: Fedora
Component: python-httpretty
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: mmassari
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.14
TreeView+ depends on / blocked
 
Reported: 2025-02-05 14:26 UTC by Karolina Surma
Modified: 2025-02-27 08:01 UTC (History)
4 users (show)

Fixed In Version: python-httpretty-1.1.4-29.fc43
Clone Of:
Environment:
Last Closed:
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Karolina Surma 2025-02-05 14:26:15 UTC
python-httpretty fails to build with Python 3.14.0a4.

There are multiple tests failing with a similar output: 
_______________ test_httpretty_should_allow_registering_regexes ________________

self = <urllib.request.HTTPSHandler object at 0x7fd9f2389010>
http_class = <class 'http.client.HTTPSConnection'>
req = <urllib.request.Request object at 0x7fd9f23d86d0>
http_conn_args = {'context': <ssl.SSLContext object at 0x7fd9f235df90>}
host = 'api.yipit.com'
h = <http.client.HTTPSConnection object at 0x7fd9f22815b0>
headers = {'Connection': 'close', 'Host': 'api.yipit.com', 'User-Agent': 'Python-urllib/3.14'}

    def do_open(self, http_class, req, **http_conn_args):
        """Return an HTTPResponse object for the request, using http_class.
    
        http_class must implement the HTTPConnection API from http.client.
        """
        host = req.host
        if not host:
            raise URLError('no host given')
    
        # will parse host:port
        h = http_class(host, timeout=req.timeout, **http_conn_args)
        h.set_debuglevel(self._debuglevel)
    
        headers = dict(req.unredirected_hdrs)
        headers.update({k: v for k, v in req.headers.items()
                        if k not in headers})
    
        # TODO(jhylton): Should this be redesigned to handle
        # persistent connections?
    
        # We want to make an HTTP/1.1 request, but the addinfourl
        # class isn't prepared to deal with a persistent connection.
        # It will try to read all remaining data from the socket,
        # which will block while the server waits for the next request.
        # So make sure the connection gets closed after the (only)
        # request.
        headers["Connection"] = "close"
        headers = {name.title(): val for name, val in headers.items()}
    
        if req._tunnel_host:
            tunnel_headers = {}
            proxy_auth_hdr = "Proxy-Authorization"
            if proxy_auth_hdr in headers:
                tunnel_headers[proxy_auth_hdr] = headers[proxy_auth_hdr]
                # Proxy-Authorization should not be sent to origin
                # server.
                del headers[proxy_auth_hdr]
            h.set_tunnel(req._tunnel_host, headers=tunnel_headers)
    
        try:
            try:
>               h.request(req.get_method(), req.selector, req.data, headers,
                          encode_chunked=req.has_header('Transfer-encoding'))

/usr/lib64/python3.14/urllib/request.py:1321: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib64/python3.14/http/client.py:1336: in request
    self._send_request(method, url, body, headers, encode_chunked)
/usr/lib64/python3.14/http/client.py:1382: in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
/usr/lib64/python3.14/http/client.py:1331: in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
/usr/lib64/python3.14/http/client.py:1091: in _send_output
    self.send(msg)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <http.client.HTTPSConnection object at 0x7fd9f22815b0>
data = b'GET /v1/deal;brand=GAP HTTP/1.1\r\nAccept-Encoding: identity\r\nHost: api.yipit.com\r\nUser-Agent: Python-urllib/3.14\r\nConnection: close\r\n\r\n'

    def send(self, data):
        """Send 'data' to the server.
        ``data`` can be a string object, a bytes object, an array object, a
        file-like object that supports a .read() method, or an iterable object.
        """
    
        if self.sock is None:
            if self.auto_open:
                self.connect()
            else:
                raise NotConnected()
    
        if self.debuglevel > 0:
            print("send:", repr(data))
        if hasattr(data, "read") :
            if self.debuglevel > 0:
                print("sending a readable")
            encode = self._is_textIO(data)
            if encode and self.debuglevel > 0:
                print("encoding file using iso-8859-1")
            while datablock := data.read(self.blocksize):
                if encode:
                    datablock = datablock.encode("iso-8859-1")
                sys.audit("http.client.send", self, datablock)
                self.sock.sendall(datablock)
            return
        sys.audit("http.client.send", self, data)
        try:
>           self.sock.sendall(data)
E           AttributeError: 'SSLContext' object has no attribute 'sendall'

/usr/lib64/python3.14/http/client.py:1055: AttributeError

During handling of the above exception, another exception occurred:

    @httprettified
    def test_httpretty_should_allow_registering_regexes():
        "HTTPretty should allow registering regexes with urllib2"
    
        HTTPretty.register_uri(
            HTTPretty.GET,
            re.compile(r"https://api.yipit.com/v1/deal;brand=(?P<brand_name>\w+)"),
            body="Found brand",
        )
    
        request = urllib2.Request(
            "https://api.yipit.com/v1/deal;brand=GAP",
        )
>       fd = urllib2.urlopen(request)

tests/functional/test_urllib2.py:334: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib64/python3.14/urllib/request.py:187: in urlopen
    return opener.open(url, data, timeout)
/usr/lib64/python3.14/urllib/request.py:487: in open
    response = self._open(req, data)
/usr/lib64/python3.14/urllib/request.py:504: in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
/usr/lib64/python3.14/urllib/request.py:464: in _call_chain
    result = func(*args)
/usr/lib64/python3.14/urllib/request.py:1369: in https_open
    return self.do_open(http.client.HTTPSConnection, req,
/usr/lib64/python3.14/urllib/request.py:1327: in do_open
    h.close()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <http.client.HTTPSConnection object at 0x7fd9f22815b0>

    def close(self):
        """Close the connection to the HTTP server."""
        self.__state = _CS_IDLE
        try:
            sock = self.sock
            if sock:
                self.sock = None
>               sock.close()   # close it manually... there may be other refs
E               AttributeError: 'SSLContext' object has no attribute 'close'


https://docs.python.org/3.14/whatsnew/3.14.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.14/fedora-rawhide-x86_64/08609135-python-httpretty/

For all our attempts to build python-httpretty with Python 3.14, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.14/package/python-httpretty/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.14:
https://copr.fedorainfracloud.org/coprs/g/python/python3.14/

Let us know here if you have any questions.

Python 3.14 is planned to be included in Fedora 43.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.14.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 mmassari 2025-02-26 10:20:10 UTC
Should be fixed with latest build in rawhide python-httpretty-1.1.4-29.fc43


Note You need to log in before you can comment on or make changes to this bug.