Getting requests.exceptions.HTTPError: 403 Client Error after a succsesfull function test

I’m using wsl2 on windows; after one successful integration test on goerli with pytest on ubuntu, I’m constantly getting this error on running my tests:

requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://goerli.infura.io/v3/MY_PROJECT_ID

Full body error is:

def test_owner_can_change_tokens_approval():
if network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
pytest.skip()
account = get_account()

  (staking, koala_Token) = deploy_KoalaToken_and_Staking()
tests/Integration/test_staking_integration.py:68:

scripts/deploy.py:10: in deploy_KoalaToken_and_Staking
koala_Token = KoalaToken.deploy(1000000000000000000000000, {“from”: account})
…/.local/lib/python3.8/site-packages/web3/eth.py:831: in send_raw_transaction
return self._send_raw_transaction(transaction)
…/.local/lib/python3.8/site-packages/web3/module.py:57: in caller
result = w3.manager.request_blocking(method_str,
…/.local/lib/python3.8/site-packages/web3/manager.py:197: in request_blocking
response = self._make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/manager.py:150: in _make_request
return request_func(method, params)
…/.local/lib/python3.8/site-packages/web3/middleware/formatting.py:94: in middleware
response = make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/middleware/gas_price_strategy.py:90: in middleware
return make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/middleware/formatting.py:94: in middleware
response = make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/middleware/attrdict.py:33: in middleware
response = make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/middleware/formatting.py:94: in middleware
response = make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/middleware/formatting.py:94: in middleware
response = make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/middleware/formatting.py:94: in middleware
response = make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/middleware/buffered_gas_estimate.py:40: in middleware
return make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/middleware/exception_retry_request.py:105: in middleware
return make_request(method, params)
…/.local/lib/python3.8/site-packages/web3/providers/rpc.py:88: in make_request
raw_response = make_post_request(
…/.local/lib/python3.8/site-packages/web3/_utils/request.py:103: in make_post_request
response.raise_for_status()

self = <Response [403]>

def raise_for_status(self):
    """Raises :class:`HTTPError`, if one occurred."""

    http_error_msg = ""
    if isinstance(self.reason, bytes):
        # We attempt to decode utf-8 first because some servers
        # choose to localize their reason strings. If the string
        # isn't utf-8, we fall back to iso-8859-1 for all other
        # encodings. (See PR #3538)
        try:
            reason = self.reason.decode("utf-8")
        except UnicodeDecodeError:
            reason = self.reason.decode("iso-8859-1")
    else:
        reason = self.reason

    if 400 <= self.status_code < 500:
        http_error_msg = (
            f"{self.status_code} Client Error: {reason} for url: {self.url}"
        )

    elif 500 <= self.status_code < 600:
        http_error_msg = (
            f"{self.status_code} Server Error: {reason} for url: {self.url}"
        )

    if http_error_msg:
      raise HTTPError(http_error_msg, response=self)
E requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://goerli.infura.io/v3/MY_PROJECT_ID

…/.local/lib/python3.8/site-packages/requests/models.py:1021: HTTPError

This is the python test script that I tried to run:

def test_owner_can_change_tokens_approval():
# Arrange
if network.show_active() in LOCAL_BLOCKCHAIN_ENVIRONMENTS:
    pytest.skip()
account = get_account()
(staking, koala_Token) = deploy_KoalaToken_and_Staking()
# Act
staking.changeTokenApproval(koala_Token, {"from": account})
# Assert
assert staking.tokenIsApproved(koala_Token) == False

And this is my deployment script:

    from brownie import KoalaToken, Staking
    from scripts.helpful_scripts import get_contract, get_account
    from web3 import Web3
    
    REMAINED_KLA_AMOUNT = Web3.toWei(1000, "ether")
    
    
    def deploy_KoalaToken_and_Staking():
        account = get_account()
        koala_Token = KoalaToken.deploy(1000000000000000000000000, {"from": account})
        staking = Staking.deploy(koala_Token, 30, {"from": account})
        tx = koala_Token.transfer(
            staking,
            koala_Token.totalSupply() - REMAINED_KLA_AMOUNT,
            {"from": account},
        )
        tx.wait(1)
        weth_token = get_contract("weth_token")
        TOKENS_PRIC_FEED_ADDRESSES = {
            koala_Token: get_contract("link_usd_price_feed"),
            weth_token: get_contract("eth_usd_price_feed"),
        }
        TOKENS_RATE = {koala_Token: 6, weth_token: 0.5}
        set_tokens_data(staking, TOKENS_PRIC_FEED_ADDRESSES, TOKENS_RATE, account)
        return staking, koala_Token
    
    
    def set_tokens_data(staking, TOKENS_PRICE_FEED_ADDRESSES, TOKENS_RATE, account):
        for token in TOKENS_PRICE_FEED_ADDRESSES:
            set_tx = staking.setTokensData(
                token,
                TOKENS_RATE[token],
                TOKENS_PRICE_FEED_ADDRESSES[token],
                {"from": account},
            )
            set_tx.wait(1)
    
        return staking

This is the original error:
External Image

External Image

External Image

The error seems to point to the python package’s requests.models. The same test was passed once on goerli, but it keeps getting HTTPError on any test script on goerli after package updating on ubuntu. The scripts were OK with ganache and also once on testnet before updating. I created another project on Infura and tried again with a new API key, but nothing’s changed.
Any help would be appreciated. Thanks a lot.

Hey, it might be a timeout that’s not properly caught. Try to extend the timeout in the provider

Web3(HTTPProvider('https://goerli.infura.io/v3/project_id'), request_kwargs={'timeout': 60})

If that doesn’t work try to run a simple getBlock and see how it goes:

from web3 import Web3, HTTPProvider

connection = Web3(HTTPProvider('https://goerli.infura.io/v3/project_id'))

print ("Latest Ethereum block number", connection.eth.blockNumber)