Skip to content

Fix: Compat netrequests for PY2 Requests - #3515

Open
Andrew-Waring wants to merge 2 commits into
pyrevitlabs:developfrom
Andrew-Waring:Requests-Fix-DotNet8.0
Open

Fix: Compat netrequests for PY2 Requests#3515
Andrew-Waring wants to merge 2 commits into
pyrevitlabs:developfrom
Andrew-Waring:Requests-Fix-DotNet8.0

Conversation

@Andrew-Waring

Copy link
Copy Markdown

Name of your PR

Compat netrequests for PY2 Requests

Description

Requests urllib not compatible with PY2 ironpython going forward for .Net 8.0

netrequests.py shim created and referenced in Compat to allow minimal update for backwards compatibility with Requests

pyrevit.compat import requests to replace import requests


Checklist

Before submitting your pull request, ensure the following requirements are met:

  • Code follows the PEP 8 style guide.
  • Code has been formatted with Black using the command:
    pipenv run black {source_file_or_directory}
  • Changes are tested and verified to work as expected.

I have tested in revit 2024, 2025, with the latest 6.5.4 WIP installer.


Related Issues


Additional Notes

It may be better to put this higher up the stack to allow backwards compatibility with requests without the need for minimal code change.

This is my first ever pull request on literally anything public on github. So please be gentle!

I did use some copilot to help write this.


Thank you for contributing to pyRevit! 🎉

@devloai

devloai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Unable to trigger custom agent "Code Reviewer". You have run out of credits 😔
Please upgrade your plan or buy additional credits from the subscription page.

@Andrew-Waring Andrew-Waring changed the title Compat netrequests for PY2 Requests Fix: Compat netrequests for PY2 Requests Jul 27, 2026
@jmcouffin
jmcouffin requested a review from Copilot July 27, 2026 19:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a .NET HttpClient-based shim (netrequests.py) intended to provide a minimal requests-like API for IronPython 2 on Revit/.NET 8, and wires it into pyrevit.compat so consumers can import requests from there for better backwards compatibility.

Changes:

  • Added pyrevit.netrequests implementing a small subset of the requests API using System.Net.Http.HttpClient.
  • Updated pyrevit.compat to conditionally expose requests (real requests on PY3, shim on PY2).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
pyrevitlib/pyrevit/netrequests.py New requests-compatible shim using .NET HttpClient, including streaming support and basic response helpers.
pyrevitlib/pyrevit/compat.py Adds conditional import to expose requests via pyrevit.compat (real vs shim).

Comment on lines +41 to +47
try:
if PY3:
import requests
else:
import pyrevit.netrequests as requests
except Exception:
import requests
Comment on lines +423 to +433
if timeout is not None:
try:
client = HttpClient()
client.Timeout = TimeSpan.FromSeconds(
float(timeout)
)
temporary_client = True
except Exception:
client = _shared_client
temporary_client = False

Comment on lines +294 to +312
def close(self):
try:
if self._reader:
self._reader.Close()
except Exception:
pass

try:
if self._response:
self._response.Dispose()
except Exception:
pass

try:
if self._client:
self._client.Dispose()
except Exception:
pass

Comment on lines +382 to +384
if not isinstance(data, str):
data = str(data)

Comment on lines +186 to +202
if not stream:
try:
self._content = (
dotnet_response.Content
.ReadAsByteArrayAsync()
.Result
)
except Exception:
self._content = b""

try:
self._text = (
dotnet_response.Content
.ReadAsStringAsync()
.Result
)
except Exception:
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

Successfully merging this pull request may close these issues.

[Bug]: Dot Net 8 Regression: Requests and SSL no longer functions under IronPython

2 participants