3

So, I had this code and it worked perfectly fine:

def upload_to_imgur(url):
    j1 = requests.post(
        "https://api.imgur.com/3/upload.json",
        headers=headers,
        data={
            'key': api_key,
            'image': b64encode(requests.get(url).content),
            'type': 'base64',
            'name': '1.jpg',
            'title': 'Picture no. 1'
        }
    )
    data = json.loads(j1.text)['data']
    return data['link']

Now, I wanted to make all this async, but that doesn't really seem to work. Here's my current code:

async def async_upload_to_imgur(url):
    image = await get_as_base64(url)
    j1 = await aiohttp.ClientSession().post(
                "https://api.imgur.com/3/upload.json",
                headers=headers,
                data={
                    'key': api_key,
                    'image': image,
                    'type': 'base64',
                    'name': '1.jpg',
                    'title': 'Picture no. 1'
                }
        )
    data = await j1.json()
    return data['link']
  1. The get_as_base64-function is not the issue.
  2. Header and Api Key are the same
  3. This is the output when I print "data" in the second example.

{'data': {'error': {'code': 1001, 'message': 'File was not uploaded correctly', 'type': 'Exception_Logged', 'exception': {}}, 'request': '/3/upload.json', 'method': 'POST'}, 'success': False, 'status': 500}

Ben
  • 33
  • 6

1 Answers1

1

It has to be the get_as_base64, for 2 reasons -:

1.) It says the file was not uploaded correctly meaning it doesn't support the URL or something like that

2.) I think you need to link a file not a link containing the file in it.

Gloww
  • 11
  • 1