ohld / igbot

🐙 Free scripts, bots and Python API wrapper. Get free followers with our auto like, auto follow and other scripts!
https://hikerapi.com/p/N2P6iqiM
Apache License 2.0
4.69k stars 1.47k forks source link

Photo Upload Error (Findings - Error Code 415: Unsupported Media Type) #1132

Closed AKwoKWH closed 4 years ago

AKwoKWH commented 4 years ago

Please follow the guide below


Before submitting an issue, make sure you have:

Purpose of your issue?


Code:

# The upload Script, but I modify some code so that I can see the response
    response = self.session.post(config.API_URL + "upload/photo/", data=m.to_string())
    try: responseJson = json.loads(response.text)
    except: responseJson = 'Non JSON'
    print('Uploading Response: ',response, response.status_code, responseJson)

Error/Debug Log:

Uploading Response:  <Response [415]> 415 Non JSON

Describe your issue

I search the Error Code , the 415 means "Unsupported Media Type" It is NOT the API endpoint changed as we previously believed.

The photo to be uploaded is a "JPG" file, so it should be supported. I guess, there are issue in the request data causing the error

steffanjensen commented 4 years ago

what command are you using the bot or the bot.api ?

AKwoKWH commented 4 years ago

Actually no different. No matter I call from "bot." or "bot.api.", it is ending up directed to the function "upload_photo" in "api_photo.py"

The "bot.py" import "upload_photo" from "bot_photo.py"

from .bot_photo import download_photo, download_photos, upload_photo

Then the "bot_photo.py" calling the api function

    result = self.api.upload_photo(
        photo,
        caption,
        upload_id,
        from_video,
        options=options
    )
AKwoKWH commented 4 years ago

1134

ghost commented 4 years ago

Did the merge fixed the issue for you ? I'm still having a "415 Unsupported Media Type" error when trying to upload a JPG photo with instabot==0.75 (latest version)

pierre-cmd commented 4 years ago

Did the merge fixed the issue for you? I'm still having a "415 Unsupported Media Type" error when trying to upload a JPG photo with instabot==0.75 (latest version)

I'm having the same issue with 0.75 (and before) and 0.76 as well. On two different accounts. The issue appears one time before, about a month ago, and disappeared by itself after about a week (not sure about the 415 error code at the time though). I hoped this would do the same this time, but it's been more than a week now, and I still got the 415 error.

Everything else seems to work fine though (follow, unfollow, retrieving feed, followers, etc...)

I call directly from the API but going through the bot result in the same error. Is everybody having this error or is it only for some of us?

untitled3000 commented 4 years ago

@pierre-cmd - I'm having the same issue. I had the issue a month ago and I'm having it again as well.

qiray commented 4 years ago

I have same problem since November 20th

JoeHO888 commented 4 years ago

Yes, the issue still occurs. Suspect that due to change in instagram private api, I couldn't upload photo in other libraries, e.g.Instagram Private API. Similar issue is raised: #215

AKwoKWH commented 4 years ago

I original think it was the API endpoint path changed (aka the path "upload/photo/") but the 415 error make me think that it might be the post data format or parameter changed

We are sending something like below:

    data = {
        "upload_id": upload_id,
        "_uuid": self.uuid,
        "_csrftoken": self.token,
        "image_compression": '{"lib_name":"jt","lib_version":"1.3.0","quality":"87"}',
        "photo": (
            "pending_media_%s.jpg" % upload_id,
            photo_bytes,
            "application/octet-stream",
            {"Content-Transfer-Encoding": "binary"},
        ),
    }
    dataEncode = MultipartEncoder(data, boundary=self.uuid).to_string()
    self.send_request(endpoint = 'upload/photo/', post=dataEncode, with_signature=False)
pierre-cmd commented 4 years ago

I original think it was the API endpoint path changed (aka the path "upload/photo/") but the 415 error make me think that it might be the post data format or parameter changed

When I tried to trace upload_photo last week, it strikes me how fast it failed, almost immediately. It doesn't feel like it got the time to upload the data (but maybe it's just super fast), so it could actually fit with an endpoint change.

I have no clue of how to find the new endpoint though or find what's wrong in the data

pierre-cmd commented 4 years ago

Something interesting is happening this morning with 0.76, instead of failing cleaningly with a 415 error, upload_photo crashes while it try to decode the Json

File "/usr/local/lib/python3.7/site-packages/instabot/api/api.py", line 791, in upload_photo self, photo, caption, upload_id, from_video, force_resize, options File "/usr/local/lib/python3.7/site-packages/instabot/api/api_photo.py", line 181, in upload_photo with_signature=False File "/usr/local/lib/python3.7/site-packages/instabot/api/api.py", line 549, in send_request response_data = json.loads(response.text) File "/usr/local/lib/python3.7/json/init.py", line 348, in loads return _default_decoder.decode(s) File "/usr/local/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/lib/python3.7/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

It crashes twice on my Nas, so I have only this callstack, but I'll try to reproduce the issue on my computer to see what the response look likes.

Anybody else is having this change of behavior this morning?

Hatchet-Harry commented 4 years ago

Hello there, The bot doesn't work for uploading for around 2 weeks now. The only message is still "XXX is not uploaded" - does someone has this issue? is it still a API endpoint issue? Any updates on this? Thanks.

pierre-cmd commented 4 years ago

The error when uploading photo change from 415 to 400 2 days ago. Besides that I have no clue :-/

Hatchet-Harry commented 4 years ago

Thanks pierre. I was curious because it looks like mgp25 found the solution.

yapizza commented 4 years ago

Thanks pierre. I was curious because it looks like mgp25 found the solution.

mgp25 very sorry but there is the same problem

Hatchet-Harry commented 4 years ago

So this is not true ? image

AKwoKWH commented 4 years ago

seem no one hv idea on the new api endpoint or what hv to be pass to the endpoint to get the pics successfully post. Anyone aware if there are other services/bot which provide auto upload works?

ostrichegret commented 4 years ago

@AKwoKWH

Use this: https://github.com/mgp25/Instagram-API/blob/3ec188af003a294803d8b17c22f1f588585384f5/src/Request/Internal.php

protected function _uploadResumablePhoto

Instagram Android now use this path:

$endpoint = sprintf('https://i.instagram.com/rupload_igphoto/%s_%d_%d', $internalMetadata->getUploadId(), 0, Utils::hashCode($photoDetails->getFilename()) );

JoeHO888 commented 4 years ago

@ostrichegret How does "%s%d%d" refer to?

ostrichegret commented 4 years ago

@JoeHO888 %$ = upload id %d = just 0 %d = hash of the filename

example: https://i.instagram.com/rupload_igphoto/195273407953726_0_-1886599878

more complete code is on the link: https://github.com/mgp25/Instagram-API/blob/3ec188af003a294803d8b17c22f1f588585384f5/src/Request/Internal.php

I haven't change the code to python too

pierre-cmd commented 4 years ago

I'm trying it myself, to python it would translate to something like

response = self.send_request( f("rupload_igphoto/{upload_id}0{some_way_to_compute_the_hash}', dataEncoded, login=True, with_signature=False )

But I have two problems so far, the first one is that I don't know how to compute this hash, the second one is that send_request seems to append 'https://i.instagram.com/api/v1/' to all request.

pierre-cmd commented 4 years ago

Ok so I wrote a dirty hack to avoid the /api/v1/ issue

And I used this piece of code to hash the file name : http://garage.pimentech.net/libcommonPython_src_python_libcommon_javastringhashcode/ which should produce java hashcode as Utils::hashCode in the php version

So when I try to upload insta_crop.jpg, I obtain the following url : https://i.instagram.com/rupload_igphoto/1576232319397_0_540101735 and it fails with a 400 error :-/

@ostrichegret the weird thing is that my hash is shorter than the one in your example. Did you provide a valid hash or just a random number as an example?

Maybe there is an issue with my hash function, or I don't hash the right string...

ostrichegret commented 4 years ago

@pierre-cmd the hash length is same, just change some numbers

pierre-cmd commented 4 years ago

@pierre-cmd the hash length is same, just change some numbers

Mine is 9 digit, your is 10 and negative, could be perfectly normal that two different string result in two different hash length, but since mine doesn't seem to works, I'm trying to find out what I missed

ostrichegret commented 4 years ago

@pierre-cmd Try this, if you can get the same result: upload.jpg = -244209036

pierre-cmd commented 4 years ago

@pierre-cmd Try this, if you can get the same result: upload.jpg = -244209036

Thanks! :) My hash function returns the same result. The problem must come from somewhere else

F-W-D commented 4 years ago

Any word on this? Is it an API change then? Has anyone found the correct route and fix?

pierre-cmd commented 4 years ago

Any word on this? Is it an API change then? Has anyone found the correct route and fix?

It's been fixed in 0.85 (not by me)

AKwoKWH commented 4 years ago

yeah, it is fixed in the lastest version. Thanks @adw0rd However, the video one seem still have issues. It return success, but the video never appear in the profile.

untitled3000 commented 4 years ago

@AKwoKWH - Yeah, I'm having the same issue. Photos are uploading but videos are not.

@pierre-cmd Any idea on what could be causing this?

adw0rd commented 4 years ago

@untitled3000 I uploading video everyday without problems

bruvv commented 4 years ago

Could be that you are soft blocked for uploading video's. When the bot reports no failes you are unable to upload due to a soft ban (https://github.com/instagrambot/instabot/issues/1194 looking into this now in this issue)