Git Product home page Git Product logo

Comments (3)

hamelsmu avatar hamelsmu commented on July 22, 2024

Possibly a dumb question on my part How would you handle proxy settings normally lets say if you were just using CURL or requests? That might help me to try to think about a solution! If you can share any examples of workarounds that you have used in the past for this, that would be helpful too!

from ghapi.

chris-sanders avatar chris-sanders commented on July 22, 2024

@hamelsmu this is a dirty hack, but since I've found it works here you go.

import fastcore.net
from ghapi.all import GhApi

if self.proxies:
    # setup proxy for requests
    self.session.proxies.update(self.proxies)
    # add proxy to fastcore which ghapi uses
    proxy = urllib.request.ProxyHandler(self.proxies)
    opener = urllib.request.build_opener(proxy)
    fastcore.net._opener = opener
self.api = GhApi(token=token)

I'm doing this to monkey patch the opener that fastcore uses on a class that's using GhApi. This does work in an environment behind a proxy, but it really would be much better if the ghapi/fastapi modules provided a way to properly configure this.

from ghapi.

chris-sanders avatar chris-sanders commented on July 22, 2024

If that snippet isn't clear enough, you can see the whole implementation using requests and ghapi behind a proxy at https://github.com/charmed-kubernetes/github-runner-operator/tree/PAT

Notice that's on a branch that isn't yet merged. If it's merged when you see this the branch will have been deleted just look in the master branch. You're looking for "/src/runner.py" for the use of requests and ghapi.

from ghapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.