subzeroid / instagrapi-rest Goto Github PK
View Code? Open in Web Editor NEWRESTful API Wrapper for Instagram Private API
Home Page: https://hikerapi.com/p/ygXxF38v
License: MIT License
RESTful API Wrapper for Instagram Private API
Home Page: https://hikerapi.com/p/ygXxF38v
License: MIT License
Hello all. I need to get register date for account. How to do it?
curl -X 'POST' \
'https://api.website.com/photo/upload' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F 'sessionid=XYZ' \ #session id works
-F '[email protected];type=image/jpeg' \
-F 'caption=cap'
Error: response status is 500
{
"detail": "{\"message\":\"login_required\",\"status\":\"fail\"}",
"exc_type": "PhotoNotUpload"
}
compose logs are:
api_1 | INFO: None [403] POST https://i.instagram.com/rupload_igphoto/1631650226816_0_1319177777 (203.0.0.29.118, Xiaomi capricorn)
api_1 | ERROR: Photo Upload failed with the following response: <Response [403]>
api_1 | INFO: 172.28.0.1:44202 - "POST /photo/upload HTTP/1.1" 500 Internal Server Error
api_1 | ERROR: Exception in ASGI application
api_1 | Traceback (most recent call last):
api_1 | File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
api_1 | result = await app(self.scope, self.receive, self.send)
api_1 | File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
api_1 | return await self.app(scope, receive, send)
api_1 | File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
api_1 | await super().__call__(scope, receive, send)
api_1 | File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
api_1 | await self.middleware_stack(scope, receive, send)
api_1 | File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
api_1 | raise exc from None
api_1 | File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
api_1 | await self.app(scope, receive, _send)
api_1 | File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
api_1 | raise exc from None
api_1 | File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
api_1 | await self.app(scope, receive, sender)
api_1 | File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 580, in __call__
api_1 | await route.handle(scope, receive, send)
api_1 | File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
api_1 | await self.app(scope, receive, send)
api_1 | File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
api_1 | response = await func(request)
api_1 | File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 201, in app
api_1 | raw_response = await run_endpoint_function(
api_1 | File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 148, in run_endpoint_function
api_1 | return await dependant.call(**values)
api_1 | File "/app/./routers/photo.py", line 138, in photo_upload
api_1 | return await photo_upload_post(
api_1 | File "/app/./helpers.py", line 33, in photo_upload_post
api_1 | return cl.photo_upload(fp.name, **kwargs)
api_1 | File "/usr/local/lib/python3.8/site-packages/instagrapi/mixins/photo.py", line 208, in photo_upload
api_1 | upload_id, width, height = self.photo_rupload(path, upload_id)
api_1 | File "/usr/local/lib/python3.8/site-packages/instagrapi/mixins/photo.py", line 170, in photo_rupload
api_1 | raise PhotoNotUpload(response.text, response=response, **last_json)
api_1 | instagrapi.exceptions.PhotoNotUpload: {"message":"login_required","status":"fail"}
It says login required but my token works on the /auth/timeline_feed
endpoint
Describe the bug
A clear and concise description of what the bug is.
download by url function doesnt work, i get an index out of range error , and when i try to "fix" it by rewriting how it saves the name of the downloaded file , i get a
Content-length=28682, but file length=9785
error
To Reproduce
Provide a piece of code to reproduce the problem.
run /video/download/by_url/
Traceback
Show your full traceback so that it is clear where exactly the error occurred.
/instagrapi-rest-main/instagrapi-rest-main/.venv/lib/python3.9/site-packages/instagrapi/mixins/video.py", line 85, in video_download_by_url
filename = "%s.%s" % (filename, fname.rsplit(".", 1)[1]) if filename else fname
IndexError: list index out of range
Expected behavior
A clear and concise description of what you expected to happen.
download a video
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Additional context
Add any other context about the problem here.
I haven't read the complete code yet but wanted to know if its possible to store and share the session to diferent devices instead of having to login every single time, I ask this because as I was trying to set it up as a service on AWS and I almost got my account locked out
http://localhost:8000/auth/login
I am trying to login. Account has 2FA . First I filled username and password after that I get the 2FA code via email and filled the input and send another request but still getting 500 error.
I am using the docker environment.
shown in the above picture Is mock data. However, I have tried with the real account but, it did not work either.
I would like to run this API on my pi, but have been unable to do so because the image this API is based on, only runs on x86.
I have managed to get it running on my pi by modifying the Dockerfile a little and copying a few (around 5) files from the https://github.com/tiangolo/uvicorn-gunicorn-docker project.
This would also reduce the project's dependance on external Docker images. Dependance could be bad if the owners disappear.
If this is something you'd be willing to support, let me know and I can make a PR.
diff --git a/Dockerfile b/Dockerfile
index 3f0cad6..1231591 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,34 @@
-FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim
+# gunicorn image
+FROM python:3.8-slim as my_gunicorn
+RUN apt-get update \
+&& apt-get install gcc ffmpeg -y \
+&& apt-get clean
+
+RUN pip install --no-cache-dir "uvicorn[standard]" gunicorn
+
+COPY uvicorn-gunicorn-docker/docker-images/start.sh /start.sh
+RUN chmod +x /start.sh
+
+COPY uvicorn-gunicorn-docker/docker-images/gunicorn_conf.py /gunicorn_conf.py
+
+COPY uvicorn-gunicorn-docker/docker-images/start-reload.sh /start-reload.sh
+RUN chmod +x /start-reload.sh
+
+COPY uvicorn-gunicorn-docker/docker-images/app /app
+WORKDIR /app/
+
+ENV PYTHONPATH=/app
+
+EXPOSE 80
+
+# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations)
+# And then will start Gunicorn with Uvicorn
+CMD ["uvicorn-gunicorn-docker/docker-images/start.sh"]
+
+
+#FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim
+FROM my_gunicorn
# RUN apt-get update \
# && apt-get install --yes --no-install-recommends \
# build-essential python-dev
@@ -13,4 +42,5 @@ COPY . /app/
WORKDIR /app
RUN pip install -r requirements.txt
-CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
\ No newline at end of file
+CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
+
I suggest that you should add more features like
Python console
>>> Client().media_pk_from_url("https://www.instagram.com/p/CTZRfJEDsE7/")
2655230362137837883
API logs:
api_1 | https://www.instagram.com/p/CTZRfJEDsE7/
api_1 | INFO: 172.28.0.1:39612 - "GET /media/pk_from_url?url=https%3A%2F%2Fwww.instagram.com%2Fp%2FCTZRfJEDsE7%2F HTTP/1.1" 200 OK
I added in a print to see the URL is correct... not sure why it's not working, and appears to be adding extra zeroes
"detail": "The username you entered doesn't appear to belong to an account. Please check your username and try again.",
"exc_type": "UnknownError"
Describe the bug
Getting invalid parameters when trying to login using 2FA.
To Reproduce
curl -X 'GET'
'http://localhost:8000/auth/login'
-H 'accept: application/json'
-H 'Content-Type: application/x-www-form-urlencoded'
-d 'username=&password=&verification_code=<2FA CODE>'
Traceback
{
"detail": "Invalid Parameters",
"exc_type": "UnknownError"
}
Expected behavior
Get sessionid.
Additional context
Using docker container.
It would be awesome (and might scalable) if the project would have "one-click deploy to Heroku" button. This will allow to use free and always on Heroku instance while spending time on the code and logic only.
Here you can find example buttons and heroku configs (with .env vars setup during onbording).
https://github.com/ohld/telegram-support-bot/blob/main/app.json
Is your feature request related to a problem? Please describe.
Then /media/user_medias
route only returns the last e.g. 50 medias, and there is no way of telling it "get the 50 medias before the 50 you fetched last time" - or in other words: paginate ;-)
Describe the solution you'd like
I'd like to have the pagination that instagrapi
provides also implemented in instagrapi-rest
. :-)
Describe alternatives you've considered
Not using instagrapi-rest... which would be a shame, because quick testing shows that it's working really nicely!
Describe the bug
I get Unprocessable Entity when passing usertags to upload a clip. (From NodeJS)
To Reproduce
const FormData = require('form-data');
const formData = new FormData();
formData.append('sessionid', sessionid);
formData.append('caption', caption);
formData.append('url', url);
formData.append(
'usertags',
`{"user": {"pk": "${userInfo.pk}", "username": "${userInfo.username}", "full_name": "${userInfo.full_name}", "profile_pic_url": "${userInfo.profile_pic_url}", "profile_pic_url_hd": "${userInfo.profile_pic_url_hd}", "stories": []}, "x": 0, "y": 0}`
);
fetch(`${process.env.INSTAGRAPI_URL}/clip/upload/by_url`, {
method: 'POST',
headers: formData.getHeaders(),
body: formData,
})
Traceback
rcplanesglobalbot-webversion-instagrapi-1 | INFO: 172.23.0.3:44116 - "POST /clip/upload/by_url HTTP/1.1" 422 Unprocessable Entity
Expected behavior
Upload the clip with the user tagged in it.
Desktop (please complete the following information):
Additional context
If I remove
formData.append(
'usertags',
`{"user": {"pk": "${userInfo.pk}", "username": "${userInfo.username}", "full_name": "${userInfo.full_name}", "profile_pic_url": "${userInfo.profile_pic_url}", "profile_pic_url_hd": "${userInfo.profile_pic_url_hd}", "stories": []}, "x": 0, "y": 0}`
);
the clip uploads correctly but when I add the 'usertags' it gives me that error.
While using instagrapi-rest, is useless to use the default behavior for instagrapi, to ask the SMS / E-mail code on input (STDIN).
https://github.com/adw0rd/instagrapi/blob/092b19713f920e13641c45899be5f3afab827cf4/instagrapi/mixins/private.py#L33
Since we run on an server, which is probably runing on a background task, there's no interaction with it.
A simple fork would be just setting a new challenge_code_handler
Stiveknx@90a2b23#diff-edcfd80d7c5e51c05a01f8fc4079088fe44e05a58382b801009203aca3c8ff3dR27
But, it should be possible to "resume" the previous one challenge.
The "resume", would just send a post to challenge url with the code.
It could be an endpoint, like this one:
Stiveknx@90a2b23#diff-edcfd80d7c5e51c05a01f8fc4079088fe44e05a58382b801009203aca3c8ff3dR65
But, I didn't find out, how to resume an Checkpoint, or specifically, how to "save" previous checkpoint data and resume it after.
Any clues?
First of all thanks for creating such a solid framework. I am kind of new to these concepts so sorry if that's a silly question. Say I deployed this repo to a google cloud service and base url for the api is now the service's url. Further, there are requests made to that url from multiple sources with different ip addresses. In that case, source of the traffic to instagram is the ip address of the virtual machine that deployed service runs on or ip addresses where requests come from?
how can i add method like cl.media_comments(media_id)
thanks
Hi
When I want to enter the session without login in relogin, I get it
{
"detail": "Session not found (e.g. after reload process), please relogin",
"exc_type": "Exception"
}
i get feedback_required error how can fix it?
Hi
I am trying to make an app using this incredible tool, however I feel some of the logic could be streamlined if the internal state of the REST API allowed for saving the session id, or at least having a mode for this. I would like to be able to:
The benefit of something like this is that I don't have to worry about storing any session id, which could change/become invalid at any time, within my application. I just need to store my IG user/pass, which can be used if and when the session id becomes invalid.
I feel like this could be quite easily achieved using the library "load_settings" and "dump_settings" and stored in a particular location, such as /etc/instagrapi-rest/user1.json, user2.json...
Then for Docker users (like myself), we can map that folder to a volume, ensuring that the state is maintained across container restarts. This also provides the benefit that the "device" info is maintained across container restarts too, so "Instagram can trust you more".
I am new to python and I really don't know how to setup this API project in windows.
Could you provide doc or detail info. for setup this project in windows?
I wonder if there's a way to get recent media by hashtag similar to the way in python:
medias = cl.hashtag_medias_recent('airplane', amount=400)
?
Thank you
Describe the bug
Whenever I send
[
{
'user': { 'pk': 'PK' }
}
]
As mentions on the /video/upload_to_story/by_url
it returns a 422 stating that {'detail': [{'loc': ['body', 'mentions', 0], 'msg': 'value is not a valid dict', 'type': 'type_error.dict'}]}
When infact it's a dict, I've even checked the SRC to verify if my data is correct and it seems like its 100% correct, even the OpenAPI doc has an error when I fill it out.
To Reproduce
Try using mentions on the OpenAPI spec, it'll return a 422
Desktop (please complete the following information):
After login successfully, how can I obtain the sessionId
to test other API requests?
curl -X 'POST' \
'http://192.168.1.250/auth/login' \
-H 'accept: application/json' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'username=XXXX&password=XXXXX&verification_code=&proxy=&locale=&timezone='
I try run command
docker-compose buld
or
docker build -t instagrapi-rest .
I get an error at the stage of installing dependencies (RUN pip install -r requirements.txt)
Collecting tqdm<5.0,>=4.11.2
Downloading tqdm-4.62.2-py2.py3-none-any.whl (76 kB)
INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. If you want to abort this run, you can press Ctrl + C to do so. To improve how pip performs, tell us what happened here: https://pip.pypa.io/surveys/backtracking
Downloading tqdm-4.62.1-py2.py3-none-any.whl (76 kB)
Downloading tqdm-4.62.0-py2.py3-none-any.whl (76 kB)
Downloading tqdm-4.61.2-py2.py3-none-any.whl (76 kB)
Downloading tqdm-4.61.1-py2.py3-none-any.whl (75 kB)
Downloading tqdm-4.61.0-py2.py3-none-any.whl (75 kB)
ERROR: Exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 173, in _main
status = self.run(options, args)
File "/usr/local/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 203, in wrapper
return func(self, options, args)
File "/usr/local/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 315, in run
requirement_set = resolver.resolve(
File "/usr/local/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 94, in resolve
result = self._result = resolver.resolve(
File "/usr/local/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py", line 472, in resolve
state = resolution.resolve(requirements, max_rounds=max_rounds)
File "/usr/local/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py", line 383, in resolve
raise ResolutionTooDeep(max_rounds)
pip._vendor.resolvelib.resolvers.ResolutionTooDeep: 2000000
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 2
Good day sir , im having issues tyring to login via /auth/login with golang and the error also occurs when using the instagrapi interface
func Login(username, password string) string { resp, err := Client.R(). SetFormData(map[string]string{ "username": username, "password": password, }).Post("/auth/login") if err != nil { log.Println(err) } if resp.StatusCode() != 200 { log.Println(errors.ErrLoginFailed) } if resp.StatusCode() == 422 { log.Println(errors.ErrIncorrectDetails) } return fmt.Sprintf("Login Sucessful into %s", username) }
Hi
how can i set proxy and timezone and every extra headers to every api ?
tnx
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.