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

Fix requests header #643

Merged
merged 5 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased](https://github.com/iamdefinitelyahuman/brownie)

### Fixed
- Http Requests now send a custom User-Agent (Fixes Kovan api requests) ([#643](https://github.com/eth-brownie/brownie/pull/643))

## [1.9.3](https://github.com/iamdefinitelyahuman/brownie/tree/v1.9.3) - 2020-06-19
### Added
- Accounts can now be unlocked on development networks ([#633](https://github.com/eth-brownie/brownie/pull/633))
Expand Down
4 changes: 1 addition & 3 deletions brownie/_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
from pathlib import Path

from brownie import network
from brownie._config import CONFIG
from brownie._config import CONFIG, __version__
from brownie.exceptions import ProjectNotFound
from brownie.utils import color, notify
from brownie.utils.docopt import docopt, levenshtein_norm

__version__ = "1.9.3"

__doc__ = """Usage: brownie <command> [<args>...] [options <args>]

Commands:
Expand Down
8 changes: 6 additions & 2 deletions brownie/_cli/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
from pythx.middleware import ClientToolNameMiddleware, GroupDataMiddleware

from brownie import project
from brownie._cli.__main__ import __version__
from brownie._config import CONFIG, _load_project_structure_config, _update_argv_from_docopt
from brownie._config import (
CONFIG,
__version__,
_load_project_structure_config,
_update_argv_from_docopt,
)
from brownie.exceptions import ProjectNotFound
from brownie.utils import color, notify
from brownie.utils.docopt import docopt
Expand Down
9 changes: 9 additions & 0 deletions brownie/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import re
import shutil
import sys
import warnings
from collections import defaultdict
from pathlib import Path
Expand All @@ -15,13 +16,21 @@

from brownie._singleton import _Singleton

__version__ = "1.9.3"

BROWNIE_FOLDER = Path(__file__).parent
DATA_FOLDER = Path.home().joinpath(".brownie")

DATA_SUBFOLDERS = ("accounts", "ethpm", "packages")

EVM_EQUIVALENTS = {"atlantis": "byzantium", "agharta": "petersburg"}

python_version = (
f"{sys.version_info.major}.{sys.version_info.minor}"
f".{sys.version_info.micro} {sys.version_info.releaselevel}"
)
REQUEST_HEADERS = {"User-Agent": f"Brownie/{__version__} (Python/{python_version})"}


class ConfigContainer:
def __init__(self):
Expand Down
4 changes: 2 additions & 2 deletions brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from hexbytes import HexBytes
from semantic_version import Version

from brownie._config import CONFIG
from brownie._config import CONFIG, REQUEST_HEADERS
from brownie.convert.datatypes import Wei
from brownie.convert.normalize import format_input, format_output
from brownie.convert.utils import (
Expand Down Expand Up @@ -1228,8 +1228,8 @@ def _fetch_from_explorer(address: str, action: str, silent: bool) -> Dict:
f"Fetching source of {color('bright blue')}{address}{color} "
f"from {color('bright blue')}{urlparse(url).netloc}{color}..."
)
response = requests.get(url, params=params)

response = requests.get(url, params=params, headers=REQUEST_HEADERS)
if response.status_code != 200:
raise ConnectionError(f"Status {response.status_code} when querying {url}: {response.text}")
data = response.json()
Expand Down
8 changes: 4 additions & 4 deletions brownie/project/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from brownie._config import (
CONFIG,
REQUEST_HEADERS,
_get_data_folder,
_load_project_compiler_config,
_load_project_config,
Expand Down Expand Up @@ -725,13 +726,12 @@ def _install_from_github(package_id: str) -> str:
if install_path.exists():
raise FileExistsError("Package is aleady installed")

headers: Dict = {}
if os.getenv("GITHUB_TOKEN"):
auth = b64encode(os.environ["GITHUB_TOKEN"].encode()).decode()
headers = {"Authorization": "Basic {}".format(auth)}
REQUEST_HEADERS.update({"Authorization": "Basic {}".format(auth)})
matnad marked this conversation as resolved.
Show resolved Hide resolved

response = requests.get(
f"https://api.github.com/repos/{org}/{repo}/tags?per_page=100", headers=headers
f"https://api.github.com/repos/{org}/{repo}/tags?per_page=100", headers=REQUEST_HEADERS
)
if response.status_code != 200:
msg = "Status {} when getting package versions from Github: '{}'".format(
Expand Down Expand Up @@ -865,7 +865,7 @@ def _load_sources(project_path: Path, subfolder: str, allow_json: bool) -> Dict:


def _stream_download(download_url: str, target_path: str) -> None:
response = requests.get(download_url, stream=True)
response = requests.get(download_url, stream=True, headers=REQUEST_HEADERS)
total_size = int(response.headers.get("content-length", 0))
progress_bar = tqdm(total=total_size, unit="iB", unit_scale=True)
content = bytes()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ current_version = 1.9.3

[bumpversion:file:setup.py]

[bumpversion:file:brownie/_cli/__main__.py]
[bumpversion:file:brownie/_config.py]

[flake8]
exclude = tests/data/*
Expand Down