views:

106

answers:

4

Here's the code in question:

#!/usr/bin/python

import pycurl

c = pycurl.Curl()
values = [
          ("key", "YOUR_API_KEY"),
          ("image", (c.FORM_FILE, "file.png"))]
# OR:     ("image", "http://example.com/example.jpg"))]

c.setopt(c.URL, "http://imgur.com/api/upload.xml")
c.setopt(c.HTTPPOST, values)

c.perform()
c.close()

I've tried to ask for help on how to copy this functionality in C#, but so far none of the answers really help because I need to use my API key or else it doesn't work.

A: 

The code itself looks straightforward. I don't know if pycurl is available as a .NET module (or whatever it's called) so that it can be used directly from ironpython. What's the problem with trying it once?

Noufal Ibrahim
+1  A: 

In C#, you can use the WebRequest class to accomplish the same. Take a look at the example toward the bottom of the page "How to: Send Data Using the WebRequest Class" for a code sample.

ars
A: 

As far as I know, you should be able to do that just fine.

One of two things will happen:

  1. It will work just fine when you import your code into IronPython

  2. IronPython will throw an error at you saying that it doesn't know where to find cURL. In this case, you will have to add it to your PATH. I believe it is in the sys module (sys.path.append("C:\..path_to_cURL")). Do this at the top of your code and it should be smooth sailing from there

Hope that helps

inspectorG4dget
A: 

pycurl appears to be a C-Extension for CPython.

To use this with IronPython you will need to use IronClad (a 'work in progress' project to allow use of c-extensions in the .Net world).

daftspaniel