![]() |
Cannot open file [ERNO 22] INVALID ARGUMENT - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Cannot open file [ERNO 22] INVALID ARGUMENT (/thread-7286.html) |
Cannot open file [ERNO 22] INVALID ARGUMENT - JoshuaKim02 - Jan-03-2018 https://gyazo.com/62c8bbc7236e1ea0fc475458b38605df ERROR I GET: https://gyazo.com/829caac4a291c7a0fb2a8e793f62e9ae I can't open the program at all! It just closes Immediately I don't think its the code because my laptop works when I launch the file, but for this pc IT JUST KEEPS CLOSING!!! (Jan-03-2018, 12:37 AM)JoshuaKim02 Wrote: https://gyazo.com/62c8bbc7236e1ea0fc475458b38605df #!/usr/bin/env python2.7 # encoding: utf-8 # Asset Reaper # Originally made by Adrian, fixed by Sparkles try: import json, time, os, re, StringIO from PIL import Image from urllib import urlencode import requests, base58 from BeautifulSoup import BeautifulSoup except: print('ERROR:: missing module(s)') exit() settings = json.loads(open('./settings/settings', 'r').read()) accounts = open('./settings/accounts', 'r').read().splitlines() sessions = [] accountIndex = 0 class rbx(): def __init__(self): self.session = requests.Session() def set_details(self, username, password): "sets cookie of session object" try: request = self.session.post('https://api.roblox.com/v2/login', data = { 'username': username, 'password': password }) if ('.ROBLOSECURITY' in self.session.cookies.keys()): return True except: pass return False def update(self, assetId, name, description, price): try: updateUrl = 'https://www.roblox.com/my/item.aspx?id={}'.format(assetId) request = self.session.get(updateUrl) if (request.status_code == 200): soup = BeautifulSoup(request.content) data = { '__EVENTTARGET': 'ctl00$cphRoblox$SubmitButtonTop', '__EVENTARGUMENT': '', '__VIEWSTATE': soup.find('input', attrs={'name': '__VIEWSTATE'}).get('value'), '__VIEWSTATEGENERATOR': soup.find('input', attrs={'name': '__VIEWSTATEGENERATOR'}).get('value'), '__EVENTVALIDATION': soup.find('input', attrs={'name': '__EVENTVALIDATION'}).get('value'), 'ctl00$cphRoblox$NameTextBox': name, 'ctl00$cphRoblox$DescriptionTextBox': description, 'ctl00$cphRoblox$SellThisItemCheckBox': 'on', 'ctl00$cphRoblox$SellForRobux': 'on', 'ctl00$cphRoblox$RobuxPrice': price, 'ctl00$cphRoblox$EnableCommentsCheckBox': 'on', 'GenreButtons2': '1', 'ctl00$cphRoblox$actualGenreSelection': '1' } request2 = self.session.post(updateUrl, data=data) if (request2.status_code == 200): return True except: pass return False def upload(self, name, assetType, datafile, groupId = 0): try: uploadUrl = 'https://www.roblox.com/build/upload' request = self.session.get(uploadUrl) soup = BeautifulSoup(request.content) rvt = soup.find('input', attrs={'name': '__RequestVerificationToken'}) if (rvt): rvt = rvt.get('value') uploadRequest = self.session.post(uploadUrl, data = { '__RequestVerificationToken': rvt, 'assetTypeId': assetType, 'groupId': settings['groupId'], 'onVerificationPage': False, 'isOggUploadEnabled': True, 'isTgaUploadEnabled': True, 'name': name }, files = {'file': ('image.png', datafile, 'image/png')}) if ('uploadedId' in uploadRequest.url): aid = re.search('uploadedId=(\d+)', uploadRequest.url) if (aid): return aid.group(1) elif ('later' in uploadRequest.url): print 'Limit Reached' time.sleep(30) else: print 'ERROR:: unknown, {}'.format(uploadRequest.url) except: pass class catalog(): """catalog api""" def __init__(self): pass @classmethod def search(self, CatalogContext = 1, PageNumber = 1, Subcategory = '', Category = '', SortType = '', AggregationFrequency = '', Keyword = ''): """simple catalog search""" queryString = {} for key, value in locals().items(): if (key != 'self' and key != 'queryString' and value != ''): queryString[key] = value queryString = urlencode(queryString) searchUrl = 'https://search.roblox.com/catalog/json?{}'.format(queryString) try: request = requests.get(searchUrl.format(queryString)) if (request.status_code == 200): return request.json() except: pass return {} @classmethod def getData(self, assetId): """gets data for asset""" assetUrl = 'https://assetgame.roblox.com/asset/?id={}' try: request = requests.get(assetUrl.format(assetId)) if (request.status_code == 200): soup = BeautifulSoup(request.content) return soup except: pass def save_asset(asset): """saves the asset as a file""" nameString = '{0}_!_{1}'.format(asset['Name'].encode('utf-8').strip(), asset['AssetTypeID']) filename = base58.b58encode(nameString)+'.png' try: xmlData = catalog.getData(asset['AssetId']) if (xmlData): dataUrl = xmlData.content.url.text dataRequest = requests.get(dataUrl) if (dataRequest.status_code == 200): data = StringIO.StringIO(dataRequest.content) filepath = './files/{}'.format(filename) img = Image.open(data) img.save(filepath) return True except: pass return False def start_upload(asset): """uploads assets""" global accountIndex global uploadCount for account in accounts: username, password = account.split(':') session = rbx() if (session.set_details(username, password) == True): sessions.append(session) else: print 'Invalid account: {}'.format(username) nameString = '{0}_!_{1}'.format(asset['Name'].encode('utf-8').strip(), asset['AssetTypeID']) filename = base58.b58encode(nameString)+'.png' name, typeId = base58.b58decode(filename.replace('.png', '')).split('_!_') session = sessions[accountIndex] name = '{0}{1}'.format(settings['namePrefix'], name) uploadAttempt = session.upload(name, typeId, open('./files/{}'.format(filename), 'rb'), settings['groupId']) if ((accountIndex+1) >= len(sessions)): accountIndex = 0 else: accountIndex += 1 if (uploadAttempt): if (session.update(uploadAttempt, name, settings['description'], settings['price']) == True): print 'Uploaded - {0}'.format(uploadAttempt) time.sleep(3) os.remove('./files/' + filename) def start_download(at, sb, af, kw, s, e): """downloads assets""" for pageNumber in range(int(s), int(e)): results = catalog.search(PageNumber = pageNumber, Subcategory = at, Category = 3, Keyword = kw, AggregationFrequency = af, SortType = sb) for a in results: saveAttempt = save_asset(a) print 'Downloaded - {0} - {1} - "{2}"'.format(a['AssetId'], saveAttempt, a['Name'].encode('utf-8').strip()[:15]) start_upload(a) def ui_main(): def title(): print ('\n' * 100) print 'Asset Reaper @ thetrex.net\n & patches by Sparkle' def ui_download(): print '> download > settings > asset type' print '12 - shirts' print '13 - t-shirts' print '14 - pants' assettype = raw_input('$ ') title() print '> download > settings > sort-by' print '0 - relevance' print '1 - most favorited' print '2 - bestselling' print '3 - recently updated' print '4 - price low to high' print '5 - price high to low' sortby = raw_input('$ ') title() print '> download > settings > aggregation frequency' print '0 - past day' print '1 - past week' print '2 - past month' print '3 - all time' aggregationfrequency = raw_input('$ ') title() print '> download > settings > keyword' keyword = raw_input('$ ') title() print '> download > settings > start page' start = raw_input('$ ') title() print '> download > settings > end page' end = raw_input('$ ') title() start_download(assettype, sortby, aggregationfrequency, keyword, start, end) def ui_upload(): print '> upload' start_upload() title() print '> waiting' print '1 - start' user_input = raw_input('$ ').lower() if (user_input == '1'): title() ui_download() ui_main() RE: Cannot open file [ERNO 22] INVALID ARGUMENT - Larz60+ - Jan-03-2018 What a mess, please read: https://python-forum.io/misc.php?action=help&hid=25 RE: Cannot open file [ERNO 22] INVALID ARGUMENT - snippsat - Jan-03-2018 I have edit your post and added coder tag,i wondered if you had manged to copy in code without indentation. We have made a change so this shall be very difficult to copy in code and lose indentation, all indentation is there is just that you have forget to us Code tag. Erno 22[INVALID ARGUMENT] Cannot open open file! - JoshuaKim02 - Jan-03-2018 https://gyazo.com/829caac4a291c7a0fb2a8e793f62e9ae This is what it says WHEN I TRY TO OPEN IT CLOSES IMMEDIATELY: https://gyazo.com/61df99e727fc73d1b43ff9701374220f Here is the python code but It works on my other laptop but I don't know why it won't on this. #!/usr/bin/env python2.7 # encoding: utf-8 # Asset Reaper # Originally made by Adrian, fixed by Sparkles try: import json, time, os, re, StringIO from PIL import Image from urllib import urlencode import requests, base58 from BeautifulSoup import BeautifulSoup except: print('ERROR:: missing module(s)') exit() settings = json.loads(open('./settings/settings', 'r').read()) accounts = open('./settings/accounts', 'r').read().splitlines() sessions = [] accountIndex = 0 class rbx(): def __init__(self): self.session = requests.Session() def set_details(self, username, password): "sets cookie of session object" try: request = self.session.post('https://api.roblox.com/v2/login', data = { 'username': username, 'password': password }) if ('.ROBLOSECURITY' in self.session.cookies.keys()): return True except: pass return False def update(self, assetId, name, description, price): try: updateUrl = 'https://www.roblox.com/my/item.aspx?id={}'.format(assetId) request = self.session.get(updateUrl) if (request.status_code == 200): soup = BeautifulSoup(request.content) data = { '__EVENTTARGET': 'ctl00$cphRoblox$SubmitButtonTop', '__EVENTARGUMENT': '', '__VIEWSTATE': soup.find('input', attrs={'name': '__VIEWSTATE'}).get('value'), '__VIEWSTATEGENERATOR': soup.find('input', attrs={'name': '__VIEWSTATEGENERATOR'}).get('value'), '__EVENTVALIDATION': soup.find('input', attrs={'name': '__EVENTVALIDATION'}).get('value'), 'ctl00$cphRoblox$NameTextBox': name, 'ctl00$cphRoblox$DescriptionTextBox': description, 'ctl00$cphRoblox$SellThisItemCheckBox': 'on', 'ctl00$cphRoblox$SellForRobux': 'on', 'ctl00$cphRoblox$RobuxPrice': price, 'ctl00$cphRoblox$EnableCommentsCheckBox': 'on', 'GenreButtons2': '1', 'ctl00$cphRoblox$actualGenreSelection': '1' } request2 = self.session.post(updateUrl, data=data) if (request2.status_code == 200): return True except: pass return False def upload(self, name, assetType, datafile, groupId = 0): try: uploadUrl = 'https://www.roblox.com/build/upload' request = self.session.get(uploadUrl) soup = BeautifulSoup(request.content) rvt = soup.find('input', attrs={'name': '__RequestVerificationToken'}) if (rvt): rvt = rvt.get('value') uploadRequest = self.session.post(uploadUrl, data = { '__RequestVerificationToken': rvt, 'assetTypeId': assetType, 'groupId': settings['groupId'], 'onVerificationPage': False, 'isOggUploadEnabled': True, 'isTgaUploadEnabled': True, 'name': name }, files = {'file': ('image.png', datafile, 'image/png')}) if ('uploadedId' in uploadRequest.url): aid = re.search('uploadedId=(\d+)', uploadRequest.url) if (aid): return aid.group(1) elif ('later' in uploadRequest.url): print 'Limit Reached' time.sleep(30) else: print 'ERROR:: unknown, {}'.format(uploadRequest.url) except: pass class catalog(): """catalog api""" def __init__(self): pass @classmethod def search(self, CatalogContext = 1, PageNumber = 1, Subcategory = '', Category = '', SortType = '', AggregationFrequency = '', Keyword = ''): """simple catalog search""" queryString = {} for key, value in locals().items(): if (key != 'self' and key != 'queryString' and value != ''): queryString[key] = value queryString = urlencode(queryString) searchUrl = 'https://search.roblox.com/catalog/json?{}'.format(queryString) try: request = requests.get(searchUrl.format(queryString)) if (request.status_code == 200): return request.json() except: pass return {} @classmethod def getData(self, assetId): """gets data for asset""" assetUrl = 'https://assetgame.roblox.com/asset/?id={}' try: request = requests.get(assetUrl.format(assetId)) if (request.status_code == 200): soup = BeautifulSoup(request.content) return soup except: pass def save_asset(asset): """saves the asset as a file""" nameString = '{0}_!_{1}'.format(asset['Name'].encode('utf-8').strip(), asset['AssetTypeID']) filename = base58.b58encode(nameString)+'.png' try: xmlData = catalog.getData(asset['AssetId']) if (xmlData): dataUrl = xmlData.content.url.text dataRequest = requests.get(dataUrl) if (dataRequest.status_code == 200): data = StringIO.StringIO(dataRequest.content) filepath = './files/{}'.format(filename) img = Image.open(data) img.save(filepath) return True except: pass return False def start_upload(asset): """uploads assets""" global accountIndex global uploadCount for account in accounts: username, password = account.split(':') session = rbx() if (session.set_details(username, password) == True): sessions.append(session) else: print 'Invalid account: {}'.format(username) nameString = '{0}_!_{1}'.format(asset['Name'].encode('utf-8').strip(), asset['AssetTypeID']) filename = base58.b58encode(nameString)+'.png' name, typeId = base58.b58decode(filename.replace('.png', '')).split('_!_') session = sessions[accountIndex] name = '{0}{1}'.format(settings['namePrefix'], name) uploadAttempt = session.upload(name, typeId, open('./files/{}'.format(filename), 'rb'), settings['groupId']) if ((accountIndex+1) >= len(sessions)): accountIndex = 0 else: accountIndex += 1 if (uploadAttempt): if (session.update(uploadAttempt, name, settings['description'], settings['price']) == True): print 'Uploaded - {0}'.format(uploadAttempt) time.sleep(3) os.remove('./files/' + filename) def start_download(at, sb, af, kw, s, e): """downloads assets""" for pageNumber in range(int(s), int(e)): results = catalog.search(PageNumber = pageNumber, Subcategory = at, Category = 3, Keyword = kw, AggregationFrequency = af, SortType = sb) for a in results: saveAttempt = save_asset(a) print 'Downloaded - {0} - {1} - "{2}"'.format(a['AssetId'], saveAttempt, a['Name'].encode('utf-8').strip()[:15]) start_upload(a) def ui_main(): def title(): print ('\n' * 100) print 'Asset Reaper @ thetrex.net\n & patches by Sparkle' def ui_download(): print '> download > settings > asset type' print '12 - shirts' print '13 - t-shirts' print '14 - pants' assettype = raw_input('$ ') title() print '> download > settings > sort-by' print '0 - relevance' print '1 - most favorited' print '2 - bestselling' print '3 - recently updated' print '4 - price low to high' print '5 - price high to low' sortby = raw_input('$ ') title() print '> download > settings > aggregation frequency' print '0 - past day' print '1 - past week' print '2 - past month' print '3 - all time' aggregationfrequency = raw_input('$ ') title() print '> download > settings > keyword' keyword = raw_input('$ ') title() print '> download > settings > start page' start = raw_input('$ ') title() print '> download > settings > end page' end = raw_input('$ ') title() start_download(assettype, sortby, aggregationfrequency, keyword, start, end) def ui_upload(): print '> upload' start_upload() title() print '> waiting' print '1 - start' user_input = raw_input('$ ').lower() if (user_input == '1'): title() ui_download() ui_main() RE: Cannot open file [ERNO 22] INVALID ARGUMENT - micseydel - Jan-04-2018 If you just have a program with print("Hello, world!")does that behave as expected? If so, then we have figured out it's related to the code, otherwise it's something else related to your environment. RE: Cannot open file [ERNO 22] INVALID ARGUMENT - JoshuaKim02 - Jan-04-2018 It doesn't let me open any python files at all, everything just keeps closing! RE: Cannot open file [ERNO 22] INVALID ARGUMENT - Gribouillis - Jan-04-2018 Does the python interpreter run in a console? What happens if you open a console and invoke python myfile.py in the console?
RE: Cannot open file [ERNO 22] INVALID ARGUMENT - JoshuaKim02 - Jan-04-2018 Is this how Im supposed https://gyazo.com/4bcfb6da83f0401ce7e4786267ea320b And I think Im getting the errors because of the korean texts https://gyazo.com/501043df77f570f98e6f2c55effc4ce7 I don't know how to remove or change it to english. RE: Cannot open file [ERNO 22] INVALID ARGUMENT - sparkz_alot - Jan-04-2018 Looks more like when you install Python, you didn't have it update your Environmental Variables. From the command terminal, type 'path', you should see the entry's "C:\Python27\" and "C:\Python27\Scripts\". If not, you need to add them. (This is assuming you installed Python at location "C:\Python27" if not, substitute the actual location. FYI, 'python.exe' is under the main directory, not the Scripts directory. RE: Cannot open file [ERNO 22] INVALID ARGUMENT - snippsat - Jan-04-2018 Add Python to Windows PATH Environment as mention. You add: C:\Python27\ C:\Python27\ScriptsThen in path it look like this C:\Python27\;C:\Python27\Scripts\; Restart PC. Now should python work from anywhere in cmd like this. Microsoft Windows [Version 10.0.15063] (c) 2017 Microsoft Corporation. Med enerett. C:\Windows\System32>cd\ C:\>python Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> exit() C:\>py -2.7 Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> exit() C:\>You should see python 2.7 start opp from root C:\ or anywhere in cmd. |