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

%pastebin returns an HTTP link when the underlying service supports HTTPS #12968

Closed
illright opened this issue May 10, 2021 · 3 comments
Closed

Comments

@illright
Copy link

Steps to reproduce

  • Execute %pastebin 1

Expected result

An HTTPS link to the paste result is returned

Actual result

An HTTP link to the paste result is returned

System info

Manjaro Linux, Python 3.9.4, IPython 7.22.0 (reproduces on IPython 8.0.0.dev)

@Lightyagami1
Copy link
Contributor

Hi I would like to take a stab at this.
looking at the code

    @line_magic
    def pastebin(self, parameter_s=''):
        """Upload code to dpaste.com, returning the URL.

        Usage:\\
          %pastebin [-d "Custom description"] 1-7

        The argument can be an input history range, a filename, or the name of a
        string or macro.

        Options:

          -d: Pass a custom description. The default will say
              "Pasted from IPython".
        """
        opts, args = self.parse_options(parameter_s, 'd:')

        try:
            code = self.shell.find_user_code(args)
        except (ValueError, TypeError) as e:
            print(e.args[0])
            return

        post_data = urlencode(
            {
                "title": opts.get("d", "Pasted from IPython"),
                "syntax": "python",
                "content": code,
            }
        ).encode("utf-8")

        request = Request(
            "http://dpaste.com/api/v2/",
            headers={"User-Agent": "IPython v{}".format(version)},
        )
        response = urlopen(request, post_data)
        return response.headers.get('Location')

the http is hard coded into endpoint of dpaste.com/api/v2/ in the code.
just changing http to https worked fine in my quick testing.

just wanted to ask, should opting for http or https be based on some parameter instead rather hardcoding the url.

@MrMino
Copy link
Member

MrMino commented Jun 19, 2021

@Lightyagami1 hardcoding the proto into the url is ok. There's no other option for it in there.

In truth, I haven't done it myself only so that someone else can come in, add this simple change, and get their first PR :).

@MrMino
Copy link
Member

MrMino commented Jul 15, 2021

Fixed in #13056

@MrMino MrMino closed this as completed Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants